-
Notifications
You must be signed in to change notification settings - Fork 2
165 lines (136 loc) · 6.17 KB
/
build.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: Build
on:
push:
branches:
- main
jobs:
commit-version-metadata:
name: Commit changes of version-metadata build output
runs-on: ubuntu-latest
defaults:
run:
working-directory: version-metadata
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2
with:
version: 9.14.4
- uses: actions/setup-node@v3
with:
node-version: 20.x
cache: pnpm
- run: pnpm install
- run: pnpm lint
- run: pnpm build
- run: pnpm licenses list --filter "version-metadata" --prod --json | npx @quantco/pnpm-licenses generate-disclaimer --json-input --output-file version-metadata/dist/licenses.txt
working-directory: .
- name: Commit changes
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git pull # the other action might have created a commit already, better pull :)
git add --force dist # have to use --force because dist is in .gitignore
git commit -m "[auto] build version-metadata: update compiled version" || true # don't fail if there are no changes
git push
commit-publish:
name: Commit changes of publish build output
runs-on: ubuntu-latest
defaults:
run:
working-directory: publish
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2
with:
version: 9.14.4
- uses: actions/setup-node@v3
with:
node-version: 20.x
cache: pnpm
- run: pnpm install
- run: pnpm lint
- run: pnpm build
- run: pnpm licenses list --filter "publish" --prod --json | npx @quantco/pnpm-licenses generate-disclaimer --json-input --output-file publish/dist/licenses.txt
working-directory: .
- name: Commit changes
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git pull # the other action might have created a commit already, better pull :)
git add --force dist # have to use --force because dist is in .gitignore
git commit -m "[auto] build publish: update compiled version" || true # don't fail if there are no changes
git push
push-tags:
name: Push tags
runs-on: ubuntu-latest
needs: [commit-version-metadata, commit-publish]
steps:
- uses: actions/checkout@v3
- uses: Quantco/ui-actions/version-metadata@v1
id: version-metadata
with:
# the version of both actions should be kept in sync
# this is enforced by the sanity check step below
file: version-metadata/package.json
token: ${{ secrets.GITHUB_TOKEN }}
- uses: Quantco/ui-actions/version-metadata@v1
id: version-metadata-sanity-check
with:
file: publish/package.json
token: ${{ secrets.GITHUB_TOKEN }}
- name: Sanity version check
if: steps.version-metadata.outputs.newVersion != steps.version-metadata-sanity-check.outputs.newVersion
run: |
echo "version-metadata and publish version do not match"
echo "version-metadata:"
echo "old: '${{ steps.version-metadata.outputs.oldVersion }}'"
echo "new: '${{ steps.version-metadata.outputs.newVersion }}'"
echo "changed: '${{ steps.version-metadata.outputs.changed }}'"
echo "type: '${{ steps.version-metadata.outputs.type }}'"
echo "publish:"
echo "old: '${{ steps.version-metadata-sanity-check.outputs.oldVersion }}'"
echo "new: '${{ steps.version-metadata-sanity-check.outputs.newVersion }}'"
echo "changed: '${{ steps.version-metadata-sanity-check.outputs.changed }}'"
echo "type: '${{ steps.version-metadata-sanity-check.outputs.type }}'"
exit 1
- name: Configure git and pull auto build commits
run: |
# configure git to use the github-actions[bot] user
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
# pull auto build commits
git pull
# fetch all tags
git fetch --tags
- name: Push v(x.x.x) tag
if: steps.version-metadata.outputs.changed == 'true'
run: |
version="${{ steps.version-metadata.outputs.newVersion }}"
git tag "v${version}"
git push origin "v${version}"
echo "pushed v${version} tag" >> $GITHUB_STEP_SUMMARY
- name: Update v(x) tag (move)
if: steps.version-metadata.outputs.changed == 'true' && steps.version-metadata.outputs.type != 'major'
run: |
# compute major version
version="${{ steps.version-metadata.outputs.newVersion }}"
major="${version%%.*}" # see https://www.linuxjournal.com/article/8919 for an explanation of this bash magic
# delete the v(x) tag locally and on the remote
git tag -d "v${major}" || echo "couldn't delete tag v${major} locally, maybe it didn't exist before, continuing.."
git push origin ":refs/tags/v${major}" || echo "couldn't delete tag v${major} remotely, maybe it didn't exist before, continuing.."
git tag "v${major}"
git push origin "v${major}"
echo "moved v${major} tag to v${version}" >> $GITHUB_STEP_SUMMARY
- name: Update v(x) tag (major version bump)
if: steps.version-metadata.outputs.changed == 'true' && steps.version-metadata.outputs.type == 'major'
run: |
# compute major version
version="${{ steps.version-metadata.outputs.newVersion }}"
major="${version%%.*}"
git tag "v${major}"
git push origin "v${major}"
echo "pushed v${major} tag" >> $GITHUB_STEP_SUMMARY
- name: Report no changes
if: steps.version-metadata.outputs.changed == 'false'
run: |
echo "No version bump detected" >> $GITHUB_STEP_SUMMARY