Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create action workflow to get latest docs changes from openzeppelin-foundry-upgrades #1129

Merged
merged 12 commits into from
Feb 21, 2025
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 --global user.name "GitHub Actions"
git config --global user.email "github-actions@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
Loading