Skip to content

Commit

Permalink
Create action workflow to get latest docs changes from openzeppelin-f…
Browse files Browse the repository at this point in the history
…oundry-upgrades (#1129)

Co-authored-by: Eric Lau <ericglau@outlook.com>
  • Loading branch information
CoveMB and ericglau authored Feb 21, 2025
1 parent 0f42a73 commit 45a957b
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches: [master]
pull_request: {}
repository_dispatch:
types: [update-foundry-submodule-docs]

concurrency:
group: checks-${{ github.ref }}
Expand Down Expand Up @@ -53,3 +55,63 @@ jobs:
run: yarn coverage

- uses: codecov/codecov-action@v5

update-foundry-submodule-docs:
if: github.event_name == 'repository_dispatch'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- name: Set up environment
uses: ./.github/actions/setup

- name: Update submodule
run: |
cd submodules/openzeppelin-foundry-upgrades
git fetch origin main
git reset --hard origin/main
- name: Regenerate docs
run: yarn docs:foundry:ci

- name: Check for changes in docs/modules/ROOT/pages/foundry/
id: check_changes
run: |
[ -n "$(git diff --name-only HEAD -- docs/modules/ROOT/pages/foundry/)" ] && echo "SHOULD_COMMIT_DOC_UPDATE=true" >> $GITHUB_ENV || true
- name: Set Git identity
if: env.SHOULD_COMMIT_DOC_UPDATE == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Create new branch, commit and push changes
if: env.SHOULD_COMMIT_DOC_UPDATE == 'true'
run: |
BRANCH_NAME="ci/update-foundry-docs-$(date +'%Y-%m-%d-%H%M%S')-${{ github.run_id }}"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
git checkout -b $BRANCH_NAME
git add docs/modules/ROOT/pages/foundry/
git commit -m "[CI] Update Foundry Upgrades plugin docs"
git push origin $BRANCH_NAME
- name: Create a Pull Request for docs changes
id: create_pull_request
if: env.SHOULD_COMMIT_DOC_UPDATE == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create --title "[CI] Update Foundry Upgrades plugin docs" \
--body "This Pull Request updates the docs for the Foundry Upgrades plugin" \
--base master \
--head $BRANCH_NAME || echo "Pull Request creation failed"
- name: Clean up branch if Pull Request creation fails
if: steps.create_pull_request.outcome == 'failure'
run: |
git push origin --delete $BRANCH_NAME
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"private": true,
"license": "MIT",
"scripts": {
"docs": "bash scripts/prepare-foundry-docs.sh && oz-docs",
"docs": "bash scripts/prepare-foundry-docs.sh && bash scripts/check-diff-docs.sh && oz-docs",
"docs:foundry:ci": "bash scripts/prepare-foundry-docs.sh && oz-docs",
"docs:watch": "oz-docs watch",
"prepare": "wsrun -ms prepare && tsc -b",
"lint": "yarn lint:path .",
Expand All @@ -30,4 +31,4 @@
"packages/*"
]
}
}
}
4 changes: 4 additions & 0 deletions scripts/check-diff-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

# Checks if Foundry docs are up to date. If this fails, commit the changes from the above commands.
git diff --exit-code docs/modules/ROOT/pages/foundry
4 changes: 1 addition & 3 deletions scripts/prepare-foundry-docs.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env bash

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

0 comments on commit 45a957b

Please sign in to comment.