-
-
Notifications
You must be signed in to change notification settings - Fork 10
117 lines (96 loc) · 3.59 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: Publish
on:
push:
jobs:
check:
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
PREVIOUS_COMMIT=$(git rev-parse HEAD^1)
BEFORE_VERSION=$(git show "${{ github.event.created && '$PREVIOUS_COMMIT' || 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: check
if: ${{ github.ref == 'refs/heads/main' && needs.check.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.check.outputs.version }}" "${{ github.event.after }}"
git push origin "${{ needs.check.outputs.version }}"
publish:
runs-on: ubuntu-latest
permissions:
packages: write
# Version changes in any branch can be published
needs: check
if: ${{ needs.check.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 --tag ${{ github.ref == 'refs/heads/main' && 'latest' || 'pre' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Report summary
run: |
set -e -o pipefail
PACKAGE_NAME=$(jq -r .name package.json)
CURRENT_VERSION=$(jq -r .version package.json)
echo "::notice title=Version published::\`$PACKAGE_NAME@$CURRENT_VERSION\`"
echo "### Version published :rocket:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "npm install $PACKAGE_NAME@$CURRENT_VERSION" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`bash" >> $GITHUB_STEP_SUMMARY
echo "pnpm add $PACKAGE_NAME@$CURRENT_VERSION" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY