|
| 1 | +name: Update Antora UI Spring |
| 2 | +description: A GitHub Action that detects if there is a new version of the Antora UI Spring artifact and creates a PR to update it. |
| 3 | + |
| 4 | +inputs: |
| 5 | + docs-branch: |
| 6 | + description: The branch where the file containing the Antora UI Spring artifact is. Default is 'docs-build' |
| 7 | + default: 'docs-build' |
| 8 | + workflow-branch-suffix: |
| 9 | + description: The suffix for the branch that will be created by the workflow with the changes, resolves to ${docs-branch}_${workflow-branch-suffix}. Default is update-antora-ui-spring |
| 10 | + default: 'update-antora-ui-spring' |
| 11 | + antora-file-path: |
| 12 | + description: Path to the Antora file containing the Antora UI Spring artifact. Default is 'antora-playbook.yml'. |
| 13 | + default: 'antora-playbook.yml' |
| 14 | + token: |
| 15 | + description: Token with write permission to pull-requests, issues and contents |
| 16 | + required: true |
| 17 | + |
| 18 | +runs: |
| 19 | + using: "composite" |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + - id: generate-branch-name |
| 23 | + name: Generate Branch Name |
| 24 | + run: echo "branch-name=${{ inputs.docs-branch }}_${{ inputs.workflow-branch-suffix }}" >> $GITHUB_OUTPUT |
| 25 | + shell: bash |
| 26 | + - id: check-existing-pr |
| 27 | + name: Check for Existing PR |
| 28 | + run: | |
| 29 | + pr_count=$(gh pr list --head ${{ steps.generate-branch-name.outputs.branch-name }} --base ${{ inputs.docs-branch }} --state open --json id | jq length) |
| 30 | + if [[ $pr_count -eq 0 ]]; then |
| 31 | + echo "continue=true" >> $GITHUB_OUTPUT |
| 32 | + else |
| 33 | + echo "Found at least one open PR, won't make any changes until the PR is closed." |
| 34 | + fi |
| 35 | + shell: bash |
| 36 | + env: |
| 37 | + GH_TOKEN: ${{ inputs.token }} |
| 38 | + - name: Delete Existing Branch If No PR Open |
| 39 | + if: ${{ steps.check-existing-pr.outputs.continue == 'true' }} |
| 40 | + run: | |
| 41 | + if git ls-remote --exit-code --heads origin "${{ steps.generate-branch-name.outputs.branch-name }}" >/dev/null 2>&1; then |
| 42 | + echo "Deleting ${{ steps.generate-branch-name.outputs.branch-name }} branch" |
| 43 | + git push -d origin ${{ steps.generate-branch-name.outputs.branch-name }} |
| 44 | + fi |
| 45 | + shell: bash |
| 46 | + - name: Get Current UI Bundle URL |
| 47 | + id: current |
| 48 | + if: ${{ steps.check-existing-pr.outputs.continue == 'true' }} |
| 49 | + run: | |
| 50 | + echo current_ui_bundle_url=$(grep -oE 'http[s]?://[^ ]+/ui-bundle.zip' -i -w ${{ inputs.antora-file-path }}) >> $GITHUB_OUTPUT |
| 51 | + shell: bash |
| 52 | + - name: Get Latest UI Bundle URL |
| 53 | + id: latest |
| 54 | + if: ${{ steps.check-existing-pr.outputs.continue == 'true' }} |
| 55 | + run: | |
| 56 | + echo latest_ui_bundle_url=$(gh api /repos/spring-io/antora-ui-spring/releases/latest | jq -r '.assets[] | select(.name == "ui-bundle.zip") | .browser_download_url') >> $GITHUB_OUTPUT |
| 57 | + echo tag_name=$(gh api /repos/spring-io/antora-ui-spring/releases/latest | jq -r '.tag_name') >> $GITHUB_OUTPUT |
| 58 | + shell: bash |
| 59 | + env: |
| 60 | + GH_TOKEN: ${{ inputs.token }} |
| 61 | + - name: Replace Current with Latest |
| 62 | + id: replace |
| 63 | + if: ${{ steps.current.outputs.current_ui_bundle_url != steps.latest.outputs.latest_ui_bundle_url }} |
| 64 | + run: | |
| 65 | + sed -i 's@${{ steps.current.outputs.current_ui_bundle_url }}@${{ steps.latest.outputs.latest_ui_bundle_url }}@g' ${{ inputs.antora-file-path }} |
| 66 | + shell: bash |
| 67 | + - name: Setup Git User |
| 68 | + run: | |
| 69 | + git config --global user.name 'github-actions[bot]' |
| 70 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 71 | + shell: bash |
| 72 | + - name: Create Commit |
| 73 | + id: commit |
| 74 | + run: | |
| 75 | + if [ "$(git status --porcelain)" ]; then |
| 76 | + git switch -c ${{ steps.generate-branch-name.outputs.branch-name }} |
| 77 | + git add . |
| 78 | + git commit -m "Update Antora Spring UI to ${{ steps.latest.outputs.tag_name }}" |
| 79 | + git push origin ${{ steps.generate-branch-name.outputs.branch-name }} |
| 80 | + echo create_pr=true >> $GITHUB_OUTPUT |
| 81 | + else |
| 82 | + echo "No changes detected, will not create a commit" |
| 83 | + echo create_pr=false >> $GITHUB_OUTPUT |
| 84 | + fi |
| 85 | + shell: bash |
| 86 | + - name: Create Pull Request |
| 87 | + if: ${{ steps.commit.outputs.create_pr == 'true' }} |
| 88 | + id: pull_request |
| 89 | + uses: actions/github-script@v7 |
| 90 | + with: |
| 91 | + script: | |
| 92 | + const { repo, owner } = context.repo; |
| 93 | + await github.rest.pulls.create({ |
| 94 | + title: 'Update Antora UI Spring to ${{ steps.latest.outputs.tag_name }}', |
| 95 | + owner: owner, |
| 96 | + repo: repo, |
| 97 | + head: '${{ steps.generate-branch-name.outputs.branch-name }}', |
| 98 | + base: '${{ inputs.docs-branch }}', |
| 99 | + }); |
| 100 | +
|
0 commit comments