|
| 1 | +name: Update Regal Docs |
| 2 | +on: |
| 3 | + workflow_dispatch: {} # Allow for manual triggers |
| 4 | + schedule: |
| 5 | + - cron: '0 6 * * *' # Daily at 6:00 UTC |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: read |
| 9 | + |
| 10 | +jobs: |
| 11 | + update-regal-docs: |
| 12 | + name: Update Regal Documentation |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Check out code |
| 16 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 17 | + with: |
| 18 | + token: ${{ secrets.GH_PUSH_TOKEN }} |
| 19 | + |
| 20 | + - name: Get latest Regal release |
| 21 | + id: latest |
| 22 | + env: |
| 23 | + GH_TOKEN: ${{ secrets.GH_PUSH_TOKEN }} |
| 24 | + run: | |
| 25 | + LATEST_VERSION=$(gh api repos/open-policy-agent/regal/releases/latest --jq '.tag_name') |
| 26 | + echo "version=$LATEST_VERSION" >> $GITHUB_OUTPUT |
| 27 | + echo "Latest Regal version: $LATEST_VERSION" |
| 28 | +
|
| 29 | + - name: Get current version |
| 30 | + id: current |
| 31 | + run: | |
| 32 | + CURRENT_VERSION=$(jq -r '.regal' docs/imported.json) |
| 33 | + echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 34 | + echo "Current Regal version: $CURRENT_VERSION" |
| 35 | +
|
| 36 | + - name: Check if update needed |
| 37 | + id: check |
| 38 | + run: | |
| 39 | + if [ "${{ steps.latest.outputs.version }}" = "${{ steps.current.outputs.version }}" ]; then |
| 40 | + echo "Already at latest version, no update needed" |
| 41 | + echo "needed=false" >> $GITHUB_OUTPUT |
| 42 | + else |
| 43 | + echo "Update needed: ${{ steps.current.outputs.version }} -> ${{ steps.latest.outputs.version }}" |
| 44 | + echo "needed=true" >> $GITHUB_OUTPUT |
| 45 | + fi |
| 46 | +
|
| 47 | + - name: Check if branch already exists |
| 48 | + if: steps.check.outputs.needed == 'true' |
| 49 | + run: | |
| 50 | + BRANCH_NAME="update-regal-${{ steps.latest.outputs.version }}" |
| 51 | + if git ls-remote --exit-code --heads origin "$BRANCH_NAME" >/dev/null 2>&1; then |
| 52 | + echo "::error::Branch '$BRANCH_NAME' already exists. A PR for this version may already be open." |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | + echo "Branch '$BRANCH_NAME' does not exist, proceeding with update" |
| 56 | +
|
| 57 | + - name: Update imported.json |
| 58 | + if: steps.check.outputs.needed == 'true' |
| 59 | + run: | |
| 60 | + jq --arg version "${{ steps.latest.outputs.version }}" '.regal = $version' docs/imported.json > docs/imported.json.tmp |
| 61 | + mv docs/imported.json.tmp docs/imported.json |
| 62 | +
|
| 63 | + - name: Run import script |
| 64 | + if: steps.check.outputs.needed == 'true' |
| 65 | + run: | |
| 66 | + cd docs |
| 67 | + VERSION=${{ steps.latest.outputs.version }} ./bin/import-regal-docs.sh |
| 68 | +
|
| 69 | + - name: Check for changes |
| 70 | + if: steps.check.outputs.needed == 'true' |
| 71 | + id: changes |
| 72 | + run: | |
| 73 | + if git diff --quiet; then |
| 74 | + echo "No changes detected after import" |
| 75 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 76 | + else |
| 77 | + echo "Changes detected" |
| 78 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 79 | + fi |
| 80 | +
|
| 81 | + - name: Configure git |
| 82 | + if: steps.check.outputs.needed == 'true' && steps.changes.outputs.has_changes == 'true' |
| 83 | + run: | |
| 84 | + git config user.name "opa-docs-bot" |
| 85 | + git config user.email "opa-docs-bot@openpolicyagent.org" |
| 86 | +
|
| 87 | + - name: Create branch and commit |
| 88 | + if: steps.check.outputs.needed == 'true' && steps.changes.outputs.has_changes == 'true' |
| 89 | + run: | |
| 90 | + BRANCH_NAME="update-regal-${{ steps.latest.outputs.version }}" |
| 91 | + git checkout -b "$BRANCH_NAME" |
| 92 | + git add -A |
| 93 | + git commit -s -m "docs: Update Regal docs to ${{ steps.latest.outputs.version }}" |
| 94 | +
|
| 95 | + - name: Push branch |
| 96 | + if: steps.check.outputs.needed == 'true' && steps.changes.outputs.has_changes == 'true' |
| 97 | + run: | |
| 98 | + BRANCH_NAME="update-regal-${{ steps.latest.outputs.version }}" |
| 99 | + git push origin "$BRANCH_NAME" |
| 100 | +
|
| 101 | + - name: Create pull request |
| 102 | + if: steps.check.outputs.needed == 'true' && steps.changes.outputs.has_changes == 'true' |
| 103 | + env: |
| 104 | + GH_TOKEN: ${{ secrets.GH_PUSH_TOKEN }} |
| 105 | + run: | |
| 106 | + VERSION="${{ steps.latest.outputs.version }}" |
| 107 | + gh pr create \ |
| 108 | + --title "docs: Update Regal docs to $VERSION" \ |
| 109 | + --body "$(cat <<EOF |
| 110 | + This PR updates the Regal documentation to $VERSION. |
| 111 | +
|
| 112 | + /cc @charlieegan3 @anderseknert |
| 113 | + EOF |
| 114 | + )" \ |
| 115 | + --reviewer charlieegan3,anderseknert |
0 commit comments