Skip to content

Commit 030d6bd

Browse files
Transpile b2ca897
1 parent 14cff4c commit 030d6bd

File tree

7 files changed

+70
-36
lines changed

7 files changed

+70
-36
lines changed
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,28 @@
11
name: Merge upstream
22

33
on:
4+
push:
5+
branches: [patches]
46
workflow_dispatch: {}
5-
schedule:
6-
- cron: '0 10 * * *'
7+
repository_dispatch:
8+
types: [Update]
9+
# client_payload: { ref: string }
10+
11+
concurrency:
12+
group: merge-${{ github.event.client_payload.ref || github.ref }}
13+
cancel-in-progress: true
714

815
jobs:
9-
update:
16+
merge:
1017
runs-on: ubuntu-latest
1118
steps:
12-
- uses: rokroskar/[email protected]
13-
env:
14-
GITHUB_TOKEN: ${{github.token}}
1519
- uses: actions/checkout@v2
1620
with:
17-
ref: upstream-patched
21+
ref: patches
1822
fetch-depth: 0
19-
ssh-key: ${{secrets.DEPLOY_KEY}}
23+
ssh-key: ${{ secrets.DEPLOY_KEY }}
2024
- run: bash scripts/upgradeable/git-user-config.sh
2125
- run: bash scripts/upgradeable/merge-upstream.sh
22-
- run: git push
26+
env:
27+
REF: ${{ github.event.client_payload.ref || github.ref}}
28+
- run: git push origin HEAD

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- uses: actions/checkout@v2
1616
- uses: actions/setup-node@v2
1717
with:
18-
node-version: 10.x
18+
node-version: 12.x
1919
- uses: actions/cache@v2
2020
id: cache
2121
with:

.github/workflows/transpile.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@ name: Transpile
33
on:
44
workflow_dispatch: {}
55
push:
6-
branches: [upstream-patched]
6+
branches: [patched/*]
7+
8+
concurrency:
9+
group: transpile
10+
cancel-in-progress: true
711

812
jobs:
913
transpile:
1014
runs-on: ubuntu-latest
15+
if: startsWith(github.ref, 'refs/heads/patched/')
1116
steps:
12-
- uses: rokroskar/[email protected]
13-
env:
14-
GITHUB_TOKEN: ${{github.token}}
17+
- run: echo ::set-output name=name::"${GITHUB_REF#refs/heads/patched/}"
18+
id: branch
1519
- uses: actions/checkout@v2
1620
with:
17-
ref: upstream-patched
1821
fetch-depth: 0
19-
ssh-key: ${{secrets.DEPLOY_KEY}}
22+
ssh-key: ${{ secrets.DEPLOY_KEY }}
2023
- uses: actions/setup-node@v1
2124
with:
22-
node-version: 10.x
25+
node-version: 12.x
2326
- uses: actions/cache@v2
2427
id: cache
2528
with:
@@ -29,5 +32,5 @@ jobs:
2932
- run: npm ci
3033
if: steps.cache.outputs.cache-hit != 'true'
3134
- run: bash scripts/upgradeable/git-user-config.sh
32-
- run: bash scripts/upgradeable/transpile-onto.sh master origin/master
33-
- run: git push origin master
35+
- run: bash scripts/upgradeable/transpile-onto.sh ${{ steps.branch.outputs.name }} origin/${{ steps.branch.outputs.name }}
36+
- run: git push origin ${{ steps.branch.outputs.name }}

UPGRADEABLE.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@
22

33
## [Branches](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/branches)
44

5-
### `upstream-patched`
5+
### `patches`
66

7-
Contains a patched version of the vanilla Contracts repo. It adds the scripts to transpile and GitHub Actions for it to work automatically, changes the package name, etc.
7+
Built on top of the `master` branch of the vanilla Contracts repo, contains the changes necessary to build this package: it adds the scripts to transpile and GitHub Actions for it to work automatically, changes the package name, etc.
88

9-
Eventually it may also include small changes to the Solidity code, such as reordering of state variables, in order to ensure storage compatibility.
9+
It can also include small changes to the Solidity code, such as reordering of state variables, in order to ensure storage compatibility.
1010

1111
It's an important goal that this branch should be easy to merge with the vanilla Contracts repo, avoiding merge conflicts as much as possible. This is necessary to reduce manual intervention and ensure automation runs smoothly.
1212

13-
### `master`
13+
This branch will not necessarily be up to date with the vanilla `master` branch, only up to the point necessary to guarantee successful merging with any new updates. In some cases it will be necessary to apply a manual merge with new changes, it is this branch that should be updated for the changes to propagate to all other branches.
1414

15-
Contains the actual transpiled code, which is generated automatically based on `upstream-patched`. The contents of this branch should never be manually changed, because they will be overwritten automatically with the transpiled version of `upstream-patched`. Instead, changes should be made in `upstream-patched`.
15+
### `patched/master`, `patched/release-vX.Y`
1616

17-
### `upstream-v3.2.0-patched`, `release-v3.2.0`
17+
These branches are the merge between `patches` and the corresponding branch from vanilla Contracts. These branches should generally not be updated manually.
1818

19-
I created thes branches in order to release `v3.2.0`, because the `master` branch was already ahead. The first is vanilla v3.2.0 with `upstream-patched` rebased onto it. The second is the transpiled version built using the script shown below.
19+
### `master`, `release-vX.Y`
20+
21+
Contains the transpiled code corresponding to the branch from vanilla Contracts of the same name. These are generated automatically based on their `patched/*` branch. These branches should never be manually updated, because they will be overwritten automatically with the transpiled version of `patched/*`. Instead, changes should be made in `patches`.
2022

2123
## [Actions Workflows](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/actions)
2224

2325
### [Merge upstream](/.github/workflows/merge-upstream.yml)
2426

25-
All this does is fetch the latest changes from vanilla Contracts repo, tries to merge them into `upstream-patched`, and then pushes the updated branch. If the merge has conflicts, the worfklow will fail. We should be notified of this so that we can manually run the merge and resolve the conflicts. This should not happen often.
26-
27-
Runs on a schedule every morning. Can also be triggered manually from the Actions page.
27+
All this does is fetch the latest changes from a corresponding branch in the vanilla Contracts repo, tries to merge them with `patches`, and then pushes the updated branch to `patched/*`. If the merge has conflicts, the worfklow will fail. We should be notified of this so that we can updated the `patches` branch resolving conflicts and trigger the merge again. This should not happen often.
2828

2929
### [Transpile](/.github/workflows/transpile.yml)
3030

31-
Runs every time `upstream-patched` is pushed to (for example as part of the Merge upstream workflow), transpiles the contents of that branch, and pushes the results as a new commit on the `master` branch.
31+
Runs every time a `patched/*` branch is pushed to (for example as part of the Merge upstream workflow), transpiles the contents of that branch, and pushes the results as a new commit on the transpiled branch.
3232

3333
### [Test](/.github/workflows/test.yml)
3434

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
11
#!/usr/bin/env bash
22

3-
set -euo pipefail -x
3+
set -euo pipefail
44

5-
git fetch 'https://github.com/OpenZeppelin/openzeppelin-contracts.git'
6-
git merge FETCH_HEAD -m 'Merge upstream openzeppelin-contracts into upstream-patched'
5+
: "${REF:="$(git rev-parse --symbolic-full-name HEAD)"}"
6+
7+
if [[ "$REF" != refs/heads/* ]]; then
8+
echo "$REF is not a branch" >&2
9+
exit 1
10+
elif [[ "$REF" == refs/heads/patches ]]; then
11+
REF=refs/heads/master
12+
fi
13+
14+
set -x
15+
16+
input="${REF#refs/heads/}"
17+
upstream="${input#patched/}"
18+
branch="patched/$upstream"
19+
20+
git checkout "$branch" 2>/dev/null || git checkout -b "$branch" origin/patches --no-track
21+
22+
git fetch 'https://github.com/OpenZeppelin/openzeppelin-contracts.git' master
23+
merge_base="$(git merge-base origin/patches FETCH_HEAD)"
24+
25+
git fetch 'https://github.com/OpenZeppelin/openzeppelin-contracts.git' "$upstream"
26+
# Check that patches is not ahead of the upstream branch we're merging.
27+
if ! git merge-base --is-ancestor "$merge_base" FETCH_HEAD; then
28+
echo "The patches branch is ahead of $upstream" >&2
29+
exit 1
30+
fi
31+
git merge origin/patches FETCH_HEAD -m "Merge upstream $upstream into $branch"

scripts/upgradeable/transpile-onto.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ git add contracts
2121

2222
git checkout --quiet --detach
2323

24-
if git rev-parse --quiet --verify "$target"; then
24+
if git rev-parse -q --verify "$target"; then
2525
git reset --soft "$target"
2626
git checkout "$target"
2727
else
2828
git checkout --orphan "$target"
29-
if [ -n "$base" ]; then
29+
if [ -n "$base" ] && git rev-parse -q --verify "$base"; then
3030
git reset --soft "$base"
3131
fi
3232
fi

scripts/upgradeable/transpile.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ npm run compile
88
# -i: use included Initializable
99
# -x: exclude all proxy contracts except Clones library
1010
# -p: emit public initializer
11-
npx @openzeppelin/upgrade-safe-transpiler -D \
11+
npx @openzeppelin/upgrade-safe-transpiler@^0.1.0 -D \
1212
-i contracts/proxy/Initializable.sol \
1313
-x 'contracts/proxy/**/*' \
1414
-x '!contracts/proxy/Clones.sol' \

0 commit comments

Comments
 (0)