Skip to content

Commit 447a509

Browse files
Amxxcoderabbitai[bot]ernestognw
authored
Github workflow for releasing the upgradeable contracts (#6218)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Ernesto García <[email protected]>
1 parent b79f58e commit 447a509

File tree

4 files changed

+127
-4
lines changed

4 files changed

+127
-4
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Release Upgradeable
2+
3+
on:
4+
workflow_dispatch: {}
5+
6+
jobs:
7+
state:
8+
name: Check state
9+
permissions:
10+
pull-requests: read
11+
if: ${{ !endsWith(github.repository, '-upgradeable') }}
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v6
15+
with:
16+
repository: ${{ github.repository }}-upgradeable
17+
ref: ${{ github.ref }}
18+
- uses: actions/checkout@v6
19+
with:
20+
ref: ${{ github.ref }}
21+
path: lib/openzeppelin-contracts
22+
- name: Set up environment
23+
uses: ./.github/actions/setup
24+
- name: Check upgradeable
25+
id: check-upgradeable
26+
run: bash scripts/release/workflow/check-upgradeable.sh
27+
outputs:
28+
publish: ${{ steps.check-upgradeable.outcome }}
29+
is_prerelease: ${{ steps.check-upgradeable.outputs.is_prerelease }}
30+
31+
# copied from release-cycle.yml
32+
publish:
33+
needs: state
34+
name: Publish to npm
35+
environment: push-upgradeable
36+
permissions:
37+
id-token: write
38+
if: needs.state.outputs.publish == 'success' # Note: changed from 'true' to 'success' to support the way publish is computed
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v6
42+
with:
43+
repository: ${{ github.repository }}-upgradeable
44+
ref: ${{ github.ref }}
45+
- uses: actions/checkout@v6
46+
with:
47+
ref: ${{ github.ref }}
48+
path: lib/openzeppelin-contracts
49+
- name: Set up environment
50+
uses: ./.github/actions/setup
51+
- id: pack
52+
name: Pack
53+
run: bash scripts/release/workflow/pack.sh
54+
env:
55+
PRERELEASE: ${{ needs.state.outputs.is_prerelease }}
56+
- name: Upload tarball artifact
57+
uses: actions/upload-artifact@v5
58+
with:
59+
name: ${{ github.ref_name }}-upgradeable
60+
path: ${{ steps.pack.outputs.tarball }}
61+
- name: Publish
62+
run: bash scripts/release/workflow/publish.sh
63+
env:
64+
TARBALL: ${{ steps.pack.outputs.tarball }}
65+
TAG: ${{ steps.pack.outputs.tag }}
66+
- name: Create Github Release
67+
uses: actions/github-script@v8
68+
env:
69+
PRERELEASE: ${{ needs.state.outputs.is_prerelease }}
70+
TARGET_COMMIT: ${{ github.ref }}
71+
REPO_SUFFIX: -upgradeable
72+
with:
73+
github-token: ${{ secrets.GH_TOKEN_UPGRADEABLE }}
74+
script: await require('./scripts/release/workflow/github-release.js')({ github, context })
75+
outputs:
76+
tarball_name: ${{ steps.pack.outputs.tarball_name }}
77+
78+
integrity_check:
79+
needs: publish
80+
name: Tarball Integrity Check
81+
runs-on: ubuntu-latest
82+
steps:
83+
- uses: actions/checkout@v6
84+
with:
85+
repository: ${{ github.repository }}-upgradeable
86+
ref: ${{ github.ref }}
87+
- name: Download tarball artifact
88+
id: artifact
89+
uses: actions/download-artifact@v6
90+
with:
91+
name: ${{ github.ref_name }}-upgradeable
92+
- name: Check integrity
93+
run: bash scripts/release/workflow/integrity-check.sh
94+
env:
95+
TARBALL: ${{ steps.artifact.outputs.download-path }}/${{ needs.publish.outputs.tarball_name }}

.github/workflows/upgradeable.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: transpile upgradeable
1+
name: Transpile upgradeable
22

33
on:
44
push:
@@ -9,11 +9,12 @@ on:
99
jobs:
1010
transpile:
1111
environment: push-upgradeable
12+
if: ${{ !endsWith(github.repository, '-upgradeable') }}
1213
runs-on: ubuntu-latest
1314
steps:
1415
- uses: actions/checkout@v6
1516
with:
16-
repository: OpenZeppelin/openzeppelin-contracts-upgradeable
17+
repository: ${{ github.repository }}-upgradeable
1718
fetch-depth: 0
1819
token: ${{ secrets.GH_TOKEN_UPGRADEABLE }}
1920
- name: Fetch current non-upgradeable branch
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# Get commit hash (short) of the reference commit (non-upgradeable version)
6+
cd lib/openzeppelin-contracts
7+
REFERENCE_COMMIT="$(git rev-parse --short HEAD)"
8+
9+
# Check that the commit message of the local commit (upgradeable version) matches the reference commit
10+
cd ../..
11+
if ! git log -1 --pretty=%B | grep -q "Transpile ${REFERENCE_COMMIT}"; then
12+
echo "Expected 'Transpile ${REFERENCE_COMMIT}' but found '$(git log -1 --pretty=%B)'"
13+
exit 1
14+
fi
15+
16+
# Read the version from the package.json, and check whether that corresponds to a pre-release
17+
VERSION="$(jq -r .version contracts/package.json)"
18+
if [[ "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
19+
PRERELEASE="false"
20+
elif [[ "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+$ ]]; then
21+
PRERELEASE="true"
22+
else
23+
echo "Invalid version"
24+
exit 1
25+
fi
26+
27+
echo "is_prerelease=${PRERELEASE}" >> "$GITHUB_OUTPUT"

scripts/release/workflow/github-release.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ module.exports = async ({ github, context }) => {
77

88
await github.rest.repos.createRelease({
99
owner: context.repo.owner,
10-
repo: context.repo.repo,
10+
repo: context.repo.repo + (process.env.REPO_SUFFIX ?? ''),
1111
tag_name: `v${version}`,
12-
target_commitish: context.sha,
12+
target_commitish: process.env.TARGET_COMMIT ?? context.sha,
1313
body: extractSection(changelog, version),
1414
prerelease: process.env.PRERELEASE === 'true',
1515
});

0 commit comments

Comments
 (0)