-
-
Notifications
You must be signed in to change notification settings - Fork 10
101 lines (80 loc) · 2.7 KB
/
publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
name: Publish
on:
push:
jobs:
version:
runs-on: ubuntu-latest
outputs:
description: "New version identifier (if changed)"
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
sparse-checkout: package.json
- name: Check version
id: version
run: |
set -e -o pipefail
BEFORE_VERSION=$(git show "${{ github.event.before }}:package.json" | jq -r .version)
AFTER_VERSION=$(git show "${{ github.event.after }}:package.json" | jq -r .version)
if [ "$BEFORE_VERSION" != "$AFTER_VERSION" ]; then
echo "Version changed from $BEFORE_VERSION to $AFTER_VERSION"
echo "version=$AFTER_VERSION" >> "$GITHUB_OUTPUT"
fi
tag:
runs-on: ubuntu-latest
permissions:
contents: write
# We only tag on pushes to main, when the version has changed
needs: version
if: github.ref == 'refs/heads/main' && ${{ needs.version.outputs.version != '' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: package.json
- name: Tag version
run: |
set -e -o pipefail
git tag "${{ needs.version.outputs.version }}" "${{ github.event.after }}"
git push origin "${{ needs.version.outputs.version }}"
publish:
runs-on: ubuntu-latest
permissions:
packages: write
# Version changes in any branch can be published
needs: version
if: ${{ needs.version.outputs.version != '' }}
steps:
- name: Checkout commit
uses: actions/checkout@v4
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: npm
registry-url: https://npm.pkg.github.com
scope: '@alveusgg'
- name: Cache optimized assets
uses: actions/cache@v4
with:
path: build/assets
key: optimized-assets-${{ hashFiles('src/assets/**') }}
restore-keys: |
optimized-assets-
- name: Install dependencies
run: npm ci
# If this push wasn't to main, add the commit hash to the version
- name: Update version
if: github.ref != 'refs/heads/main'
run: |
set -e -o pipefail
CURRENT_VERSION=$(jq -r .version package.json)
NEW_VERSION="$CURRENT_VERSION-pre.${{ github.event.after }}"
npm version --no-git-tag-version "$NEW_VERSION"
- name: Publish package
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}