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