Skip to content

Commit e37e786

Browse files
Create update-antora-ui-spring action
1 parent 075e9f6 commit e37e786

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

Diff for: README.adoc

+39
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,42 @@ Example usage:
8686
docs-ssh-host-key: ${{ secrets.DOCS_SSH_HOST_KEY }}
8787
dry-run: true
8888
----
89+
90+
== update-antora-ui-spring
91+
92+
A GitHub Reusable Workflow that detects if there is a new version of the https://github.com/spring-io/antora-ui-spring[Antora UI Spring] artifact and creates a PR to update the `antora-playbook.yml` file to use the new version.
93+
94+
[source,yml]
95+
----
96+
inputs:
97+
docs-branch:
98+
description: The branch where the antora-playbook.yml file is. Default is docs-build
99+
default: 'docs-build'
100+
workflow-branch:
101+
description: The branch that will be created by the workflow with the changes. Default is update-antora-ui-spring
102+
default: 'update-antora-ui-spring'
103+
token:
104+
description: Token with write permission to pull-requests, issues and contents
105+
required: true
106+
----
107+
108+
Example usage:
109+
110+
.github/workflows/update-antora-ui-spring.yml
111+
[source,yml,subs=attributes+]
112+
----
113+
permissions:
114+
pull-requests: write
115+
issues: write
116+
contents: write
117+
118+
jobs:
119+
update-antora-ui-spring:
120+
runs-on: ubuntu-latest
121+
name: Update Antora UI Spring
122+
steps:
123+
- uses: spring-io/spring-docs-actions/update-antora-spring-ui@{ACTION_VERSION}
124+
with:
125+
token: ${{ secrets.GITHUB_TOKEN }}
126+
127+
----

Diff for: update-antora-spring-ui/action.yml

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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

Comments
 (0)