-
Notifications
You must be signed in to change notification settings - Fork 1.4k
177 lines (147 loc) · 6.84 KB
/
pr-validate-changesets.yaml
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
name: Validate Changesets
on:
pull_request:
types:
- opened
- edited
- synchronize
permissions:
contents: write
jobs:
create-changeset:
name: Create Changeset
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.client_payload.ref }}
# workaround to ensure changeset file is pushed with REPO_TOKEN owner's account
# see https://github.com/changesets/action/issues/70
persist-credentials: false
- name: Setup PNPM
uses: pnpm/action-setup@v4
with:
version: 9.4.0
run_install: true
- name: Install jq
run: sudo apt-get install -y jq
- name: Run dependabot changeset script
run: pnpm changeset:dependabot
env:
PR_TITLE: ${{ github.event.pull_request.title }}
- name: Set up .netrc file
run: |
echo "machine github.com" > $HOME/.netrc
echo "login github-actions[bot]" >> $HOME/.netrc
echo "password ${{ secrets.REPO_TOKEN }}" >> $HOME/.netrc
chmod 600 $HOME/.netrc
- name: Commit Changeset
run: |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config user.name "github-actions[bot]"
git add .
git commit -m "build: update dependency changeset"
git push origin HEAD:${{ github.event.pull_request.head.ref }}
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
validate-changeset:
name: Validate PR Changeset
if: startsWith(github.head_ref, 'changeset-release') != true
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: CI Setup
uses: ./.github/actions/ci-setup
- name: Validate Changeset
run: pnpm changeset status --since=origin/${{ github.base_ref }}
- name: Validate Changeset Content
run: |
CHANGESET_FILE=$(git diff --diff-filter=A --name-only origin/${{ github.base_ref }} .changeset/*.md)
if [ -z "$CHANGESET_FILE" ]; then
# A PR doesn't have to have a changeset when packages aren't affected
# e.g. when a script is added in the scripts folder
exit 0
fi
echo "CHANGESET_FILE=$(echo "$CHANGESET_FILE")" >> $GITHUB_ENV
AFFECTED_PACKAGES=$(sed -n '/---/,/---/p' "$CHANGESET_FILE" | sed '/---/d')
if [ -z "$AFFECTED_PACKAGES" ]; then
# The changelog logic ignores changesets that don't affect any packages so we can ignore them here as well,
# because this changeset linting logic is only for changesets who's PRs will be referenced in the changelog.
# The relevant changelog logic is here:
# https://github.com/FuelLabs/fuels-ts/blob/155b6f2fe28e988b277dac231af6d6a0cff1df0c/scripts/changeset/get-full-changelog.mts#L77
exit 0
fi
# TODO: Remove once v1.0.0 is released.
# Minor changes are treated as breaking until v1.0.0 is released.
if echo "$AFFECTED_PACKAGES" | grep -q 'minor'; then
if ! echo "$PR_TITLE" | grep -q '!'; then
echo "Changeset has `minor` changes. Please mark the PR as breaking by adding an exclamation mark to its title (e.g. fix!: xxx) or use a `patch` instead."
exit 1
fi
fi
CHANGESET_DESCRIPTION=$(sed 's/^\s*\|\s*$//g' "$CHANGESET_FILE" | tail -n1)
if [ "$CHANGESET_DESCRIPTION" != "$PR_TITLE" ]; then
echo "Changeset content does not match PR title. Please update the changeset to match the PR title."
echo "Changeset file: $CHANGESET_FILE"
echo "Changeset content:"
cat "$CHANGESET_FILE"
exit 1
fi
env:
PR_TITLE: ${{ github.event.pull_request.title }}
- name: Validate added changeset will be deleted
if: ${{ env.CHANGESET_FILE != '' }}
run: |
pnpm changeset version
if git status --porcelain .changeset | grep -q "D $CHANGESET_FILE"; then
git reset --hard
exit 0
fi
# Throw if changeset not in deleted changesets
echo "Changeset file $CHANGESET_FILE will not get deleted in the changesets PR. Check its affected packages."
exit 1
env:
CHANGESET_FILE: ${{ env.CHANGESET_FILE }}
- name: Validate release/* branch changesets
if: startsWith(github.base_ref, 'release/')
run: |
LATEST_RELEASE=$(pnpm run --silent changeset:get-latest-release)
pnpm changeset version
RELEASE_VERSION=v$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' packages/fuels/package.json)
git reset --hard
pnpm add --global semver
RELEASE_VERSION_HIGHER_THAN_LATEST=$(semver $LATEST_RELEASE $RELEASE_VERSION | tail -n1 | grep ${RELEASE_VERSION#v} --silent && echo true || echo false)
CHANGES=$(sed -n '/---/,/---/p' .changeset/*.md)
if [ "$RELEASE_VERSION_HIGHER_THAN_LATEST" = "true" ]; then
echo $CHANGES | grep -E 'patch|minor' --silent && echo "Patch or minor changes found." || (echo "No patch nor minor changes found." && exit 1)
echo $CHANGES | grep -E 'major' --silent && echo "The latest release can have a patch or minor version update; no major version updates allowed." && exit 1 || echo "No major changes."
else
echo $CHANGES | grep -E 'patch' --silent && echo "Patch changes found." || (echo "No patch changes found." && exit 1)
echo $CHANGES | grep -E 'minor|major' --silent && echo "Old releases can only be patched; no minor and major version updates allowed." && exit 1 || echo "No minor nor major changes."
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Validate that there was no release for the next version
run: |
OLD_VERSION=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' packages/fuels/package.json)
pnpm changeset version
NEW_VERSION=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' packages/fuels/package.json)
git reset --hard
if [ "$OLD_VERSION" = "$NEW_VERSION" ]; then
# the versions didn't change so we won't be releasing it anyways
exit 0
fi
STATUS_CODE=$(curl -s -w '%{http_code}\n' "https://www.npmjs.com/package/fuels/v/$NEW_VERSION" | tail -n1)
if [[ $STATUS_CODE != 404 ]]; then
echo "Release for version $NEW_VERSION already exists or curl received an unexpected result (result is $STATUS_CODE). Exiting."
exit 1
else
exit 0
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}