-
Notifications
You must be signed in to change notification settings - Fork 3
183 lines (159 loc) · 8.56 KB
/
bump_version.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# Workflow which bumps the version of all packages in the repo
name: bump_version
on:
# run manually
workflow_dispatch:
inputs:
version:
type: string
description: Version number (e.g. 1.2.3)
required: true
src:
type: string
description: Source branch name (e.g. staging)
required: true
default: staging
interim:
type: string
description: Interim branch name (e.g. release/1.2.3). Leave empty to use 'release/<version_number>'.
required: false
dest:
type: string
description: Destination branch name (e.g. main)
required: true
default: main
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
GITHUB_TOKEN: ${{ secrets.PROSOPONATOR_PAT }}
GH_TOKEN: ${{ secrets.PROSOPONATOR_PAT }}
CARGO_TERM_COLOR: always
NODE_OPTIONS: "--max-old-space-size=4096"
defaults:
run:
shell: bash
jobs:
bump_version:
runs-on: ubuntu-latest
steps:
- name: Print contexts
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
ENV_CONTEXT: ${{ toJson(env) }}
VARS_CONTEXT: ${{ toJson(vars) }}
JOB_CONTEXT: ${{ toJson(job) }}
STEPS_CONTEXT: ${{ toJson(steps) }}
RUNNER_CONTEXT: ${{ toJson(runner) }}
SECRETS_CONTEXT: ${{ toJson(secrets) }}
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
MATRIX_CONTEXT: ${{ toJson(matrix) }}
NEEDS_CONTEXT: ${{ toJson(needs) }}
INPUTS_CONTEXT: ${{ toJson(inputs) }}
run: |
echo "******************************"
echo "github:" "$GITHUB_CONTEXT"
echo "******************************"
echo "env:" "$ENV_CONTEXT"
echo "******************************"
echo "vars:" "$VARS_CONTEXT"
echo "******************************"
echo "job:" "$JOB_CONTEXT"
echo "******************************"
echo "steps:" "$STEPS_CONTEXT"
echo "******************************"
echo "runner:" "$RUNNER_CONTEXT"
echo "******************************"
echo "secrets:" "$SECRETS_CONTEXT"
echo "******************************"
echo "strategy:" "$STRATEGY_CONTEXT"
echo "******************************"
echo "matrix:" "$MATRIX_CONTEXT"
echo "******************************"
echo "needs:" "$NEEDS_CONTEXT"
echo "******************************"
echo "inputs:" "$INPUTS_CONTEXT"
echo "******************************"
- uses: actions/checkout@v4
with:
submodules: "recursive"
fetch-depth: 0 # Fetch all history for all branches
- uses: actions/setup-node@v4
with:
node-version-file: 'package.json'
- run: npm i -g "npm@$(jq -r .engines.npm < package.json)"
- run: mkdir -p ~/.npm
- run: mkdir -p ~/.cache/Cypress
- name: Restore npm cache
if: ${{ runner.environment != 'self-hosted' }} # don't restore cache on self-hosted runners, network speed not good enough
uses: actions/cache/restore@v4
with:
# must restore all cache dirs, and they must exist ahead of this!
path: |
~/.npm
~/.cache/Cypress
# note that restoring a cache in github is a pain. The trailing '-' matches any string after the '-', therefore 'abc-' would match a cache named 'abc-1234' or 'abc-5678', etc.
# the problem is 'abc-' will not match a cache named 'abc'! So if you're using wildcard cache name selectors like this, you need a field that changes as the suffix to become the wildcard
# here we're setting the key to an unused cache key so it falls back to the wildcard selector in `restore-keys`
key: some-unused-cache-key
restore-keys: |
npm-${{ runner.os }}-${{ runner.arch }}-
- name: Bump version
run: |
set -euo pipefail # stop on errors, print commands, fail on pipe fails
# set the author in git
git config user.name "prosoponator[bot]"
git config user.email "[email protected]"
# check the source branch (e.g. staging) is up-to-date with the dest branch (e.g. main)
if [ "$(git rev-list --count origin/${{ github.event.inputs.src }}..origin/${{ github.event.inputs.dest }})" -ne 0 ]; then
echo "Source branch ${{ github.event.inputs.src }} is not up-to-date with destination branch ${{ github.event.inputs.dest }}. PR destination branch into the source branch and try again."
exit 1
else
echo "Source branch ${{ github.event.inputs.src }} is up-to-date with destination branch ${{ github.event.inputs.dest }}"
fi
# checkout the src branch
git checkout ${{ github.event.inputs.src }}
INTERIM="${{ github.event.inputs.interim}}"
# set the interim branch name to release/<version_number> if not provided
INTERIM="${INTERIM:-release/${{ github.event.inputs.version }}}"
# make a new branch for the version changes
git switch -c $INTERIM
pkgJsons=$(find "${{ github.workspace }}" -type f -name "package.json" -not -path "**/node_modules/**" -not -path "**/.next/**" | xargs -I "{}" echo {} | sed s/\"//g)
echo $pkgJsons
# get the package "name" out of each pkgJson
pkgNames=$(xargs -I % sh -c "jq -r '.name' %" <<< "$pkgJsons")
echo $pkgNames
while IFS= read -r pkgJson; do
echo "Bumping version in $pkgJson"
# for each package in the workspace, set the version number
cat $pkgJson | jq ".version = \"${{ github.event.inputs.version }}\"" > tmp
mv tmp $pkgJson
while IFS= read -r pkgName; do
# for each package in the workspace, check whether it is in the dependencies of the current package
# if so, bump the version number in the dependencies
cat $pkgJson | jq "if .dependencies[\"$pkgName\"] then .dependencies[\"$pkgName\"] = \"${{ github.event.inputs.version }}\" else . end" > tmp
mv tmp $pkgJson
cat $pkgJson | jq "if .devDependencies[\"$pkgName\"] then .devDependencies[\"$pkgName\"] = \"${{ github.event.inputs.version }}\" else . end" > tmp
mv tmp $pkgJson
done <<< "$pkgNames"
done <<< "$pkgJsons"
# need to bump the PROSOPO_PACKAGE_VERSION variable in env files
envFiles=$(find . -iregex ".*\/\.?env\.\w+" -not -iname "*\.js" -not -iname "*\.ts" -not -path "./node_modules/**")
echo "Bumping version in env files: $envFiles"
for envFile in $envFiles; do
sed -i "s/PROSOPO_PACKAGE_VERSION=.*/PROSOPO_PACKAGE_VERSION=${{ github.event.inputs.version }}/g" $envFile
done
# the json may be poorly formatted now, so we need to fix it
npm i
npm run -w @prosopo/scripts build
npm run -w @prosopo/lint build
npm run lint-fix
# commit the version changes
git add .
git commit -m "Bump version to ${{ github.event.inputs.version }}"
# push version changes
git push --set-upstream origin $INTERIM
# fetch the dest branch
git fetch origin ${{ github.event.inputs.dest }}
# create a PR for the release
gh pr create --base ${{ github.event.inputs.dest }} --title "Release ${{ github.event.inputs.version }}" --fill