Skip to content

Commit 45a957b

Browse files
CoveMBericglau
andauthored
Create action workflow to get latest docs changes from openzeppelin-foundry-upgrades (#1129)
Co-authored-by: Eric Lau <[email protected]>
1 parent 0f42a73 commit 45a957b

File tree

4 files changed

+70
-5
lines changed

4 files changed

+70
-5
lines changed

.github/workflows/checks.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
push:
55
branches: [master]
66
pull_request: {}
7+
repository_dispatch:
8+
types: [update-foundry-submodule-docs]
79

810
concurrency:
911
group: checks-${{ github.ref }}
@@ -53,3 +55,63 @@ jobs:
5355
run: yarn coverage
5456

5557
- uses: codecov/codecov-action@v5
58+
59+
update-foundry-submodule-docs:
60+
if: github.event_name == 'repository_dispatch'
61+
runs-on: ubuntu-latest
62+
63+
steps:
64+
- uses: actions/checkout@v4
65+
with:
66+
submodules: true
67+
fetch-depth: 0
68+
69+
- name: Set up environment
70+
uses: ./.github/actions/setup
71+
72+
- name: Update submodule
73+
run: |
74+
cd submodules/openzeppelin-foundry-upgrades
75+
git fetch origin main
76+
git reset --hard origin/main
77+
78+
- name: Regenerate docs
79+
run: yarn docs:foundry:ci
80+
81+
- name: Check for changes in docs/modules/ROOT/pages/foundry/
82+
id: check_changes
83+
run: |
84+
[ -n "$(git diff --name-only HEAD -- docs/modules/ROOT/pages/foundry/)" ] && echo "SHOULD_COMMIT_DOC_UPDATE=true" >> $GITHUB_ENV || true
85+
86+
- name: Set Git identity
87+
if: env.SHOULD_COMMIT_DOC_UPDATE == 'true'
88+
run: |
89+
git config user.name "github-actions[bot]"
90+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
91+
92+
- name: Create new branch, commit and push changes
93+
if: env.SHOULD_COMMIT_DOC_UPDATE == 'true'
94+
run: |
95+
BRANCH_NAME="ci/update-foundry-docs-$(date +'%Y-%m-%d-%H%M%S')-${{ github.run_id }}"
96+
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
97+
git checkout -b $BRANCH_NAME
98+
git add docs/modules/ROOT/pages/foundry/
99+
git commit -m "[CI] Update Foundry Upgrades plugin docs"
100+
git push origin $BRANCH_NAME
101+
102+
- name: Create a Pull Request for docs changes
103+
id: create_pull_request
104+
if: env.SHOULD_COMMIT_DOC_UPDATE == 'true'
105+
env:
106+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
run: |
108+
gh pr create --title "[CI] Update Foundry Upgrades plugin docs" \
109+
--body "This Pull Request updates the docs for the Foundry Upgrades plugin" \
110+
--base master \
111+
--head $BRANCH_NAME || echo "Pull Request creation failed"
112+
113+
- name: Clean up branch if Pull Request creation fails
114+
if: steps.create_pull_request.outcome == 'failure'
115+
run: |
116+
git push origin --delete $BRANCH_NAME
117+

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"private": true,
44
"license": "MIT",
55
"scripts": {
6-
"docs": "bash scripts/prepare-foundry-docs.sh && oz-docs",
6+
"docs": "bash scripts/prepare-foundry-docs.sh && bash scripts/check-diff-docs.sh && oz-docs",
7+
"docs:foundry:ci": "bash scripts/prepare-foundry-docs.sh && oz-docs",
78
"docs:watch": "oz-docs watch",
89
"prepare": "wsrun -ms prepare && tsc -b",
910
"lint": "yarn lint:path .",
@@ -30,4 +31,4 @@
3031
"packages/*"
3132
]
3233
}
33-
}
34+
}

scripts/check-diff-docs.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
# Checks if Foundry docs are up to date. If this fails, commit the changes from the above commands.
4+
git diff --exit-code docs/modules/ROOT/pages/foundry

scripts/prepare-foundry-docs.sh

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

33
rm -rf docs/modules/ROOT/pages/foundry
4-
cp -r submodules/openzeppelin-foundry-upgrades/docs/modules docs/modules/ROOT/pages/foundry
5-
# Checks if Foundry docs are up to date. If this fails, commit the changes from the above commands.
6-
git diff --exit-code docs/modules/ROOT/pages/foundry
4+
cp -r submodules/openzeppelin-foundry-upgrades/docs/modules docs/modules/ROOT/pages/foundry

0 commit comments

Comments
 (0)