Skip to content

Commit 56f08cb

Browse files
committed
Move script to separate action and run for PRs
1 parent 5167c81 commit 56f08cb

File tree

3 files changed

+85
-63
lines changed

3 files changed

+85
-63
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Check release
2+
description: Check for conflicts in packages being released in this PR.
3+
4+
inputs:
5+
before:
6+
description: 'The commit SHA before the current commit or pull request.'
7+
required: true
8+
9+
runs:
10+
using: composite
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Check commits for changes in released packages
18+
shell: bash
19+
env:
20+
BEFORE: ${{ inputs.before }}
21+
run: |
22+
set -euo pipefail
23+
git fetch origin main
24+
25+
mapfile -t PACKAGES < <(find packages -maxdepth 2 -name "package.json" -not -path "*/node_modules/*")
26+
RELEASED_PACKAGES=()
27+
28+
# Get all packages being released in this PR
29+
for package in "${PACKAGES[@]}"; do
30+
MAIN_VERSION=$(git show "refs/remotes/origin/main:$package" | jq -r .version)
31+
HEAD_VERSION=$(jq -r .version "$package")
32+
33+
if [ "$HEAD_VERSION" != "$MAIN_VERSION" ]; then
34+
package_name=$(jq -r ".name" "$package")
35+
echo "📦 Package \`$package_name\` is being released (version \`$MAIN_VERSION\` -> \`$HEAD_VERSION\`)"
36+
RELEASED_PACKAGES+=("$package")
37+
fi
38+
done
39+
40+
# Get all files changed ahead of this PR.
41+
git diff --name-only "$BEFORE..$(git merge-base HEAD refs/remotes/origin/main)" > changed-files.txt
42+
43+
CONFLICTS=()
44+
for package in "${RELEASED_PACKAGES[@]}"; do
45+
package_directory=$(dirname "$package")
46+
if grep -q "^$package_directory/" changed-files.txt; then
47+
CONFLICTS+=("$package_directory")
48+
fi
49+
done
50+
51+
if [ ${#CONFLICTS[@]} -ne 0 ]; then
52+
mapfile -t CONFLICTS < <(printf "%s\n" "${CONFLICTS[@]}" | sort -u)
53+
fi
54+
55+
if [ ${#CONFLICTS[@]} -ne 0 ]; then
56+
for conflict in "${CONFLICTS[@]}"; do
57+
package_name=$(jq -r ".name" "$conflict/package.json")
58+
echo "::error::Release conflict detected in \`$package_name\`. This package is being released in this PR, but files in the package were also modified ahead of this PR. Please ensure that all changes are included in the release."
59+
done
60+
exit 1
61+
else
62+
echo "✅ No release conflicts detected."
63+
fi

.github/workflows/check-release.yml

Lines changed: 0 additions & 55 deletions
This file was deleted.

.github/workflows/main.yml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,29 @@ jobs:
6363
needs: check-workflows
6464
uses: ./.github/workflows/lint-build-test.yml
6565

66+
check-release:
67+
name: Check release
68+
needs: check-workflows
69+
runs-on: ubuntu-latest
70+
steps:
71+
- name: Check if the commit or pull request is a release
72+
id: is-release
73+
uses: MetaMask/action-is-release@d063725cd15ee145d7e795a2e77db31a3e3f2c92
74+
with:
75+
commit-starts-with: 'Release [version],Release v[version],Release/[version],Release/v[version],Release `[version]`'
76+
commit-message: ${{ github.event.pull_request.title }}
77+
before: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || github.event.before }}
78+
79+
- name: Check for release conflicts
80+
if: steps.is-release.outputs.IS_RELEASE == 'true'
81+
uses: ./.github/actions/check-release
82+
with:
83+
before: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || github.event.before }}
84+
6685
is-release:
6786
name: Determine whether this is a release merge commit
6887
needs: lint-build-test
69-
if: github.event_name == 'push' || github.event_name == 'merge_group'
88+
if: github.event_name == 'push'
7089
runs-on: ubuntu-latest
7190
outputs:
7291
IS_RELEASE: ${{ steps.is-release.outputs.IS_RELEASE }}
@@ -76,16 +95,10 @@ jobs:
7695
with:
7796
commit-starts-with: 'Release [version],Release v[version],Release/[version],Release/v[version],Release `[version]`'
7897

79-
check-release:
80-
name: Check release
81-
needs: is-release
82-
if: needs.is-release.outputs.IS_RELEASE == 'true' && github.event_name == 'merge_group'
83-
uses: ./.github/workflows/check-release.yml
84-
8598
publish-release:
8699
name: Publish release
87100
needs: is-release
88-
if: needs.is-release.outputs.IS_RELEASE == 'true' && github.event_name == 'push'
101+
if: needs.is-release.outputs.IS_RELEASE == 'true'
89102
permissions:
90103
contents: write
91104
uses: ./.github/workflows/publish-release.yml
@@ -106,6 +119,7 @@ jobs:
106119
runs-on: ubuntu-latest
107120
needs:
108121
- analyse-code
122+
- check-release
109123
- lint-build-test
110124
outputs:
111125
passed: ${{ steps.set-output.outputs.passed }}

0 commit comments

Comments
 (0)