Skip to content

Commit a722fe2

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

File tree

2 files changed

+149
-0
lines changed

2 files changed

+149
-0
lines changed

Diff for: README.adoc

+49
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,52 @@ 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 Action that detects if there is a new version of the Antora UI Spring artifact and creates a PR to update it.
93+
94+
[source,yml]
95+
----
96+
inputs:
97+
docs-branch:
98+
description: The branch where the file containing the Antora UI Spring artifact is. Default is 'docs-build'
99+
default: 'docs-build'
100+
workflow-branch-suffix:
101+
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
102+
default: 'update-antora-ui-spring'
103+
antora-file-path:
104+
description: Path to the Antora file containing the Antora UI Spring artifact. Default is 'antora-playbook.yml'.
105+
default: 'antora-playbook.yml'
106+
token:
107+
description: Token with write permission to pull-requests, issues and contents
108+
required: true
109+
----
110+
111+
Example usage:
112+
113+
.github/workflows/update-antora-ui-spring.yml
114+
[source,yml,subs=attributes+]
115+
----
116+
permissions:
117+
pull-requests: write
118+
issues: write
119+
contents: write
120+
121+
jobs:
122+
update-antora-ui-spring:
123+
runs-on: ubuntu-latest
124+
name: Update Antora UI Spring
125+
strategy:
126+
matrix:
127+
branch: ['main', 'docs-build']
128+
steps:
129+
- uses: spring-io/spring-docs-actions/update-antora-spring-ui@{ACTION_VERSION}
130+
name: Update antora-playbook.yml
131+
with:
132+
docs-branch: ${{ matrix.branch }}
133+
token: ${{ secrets.GITHUB_TOKEN }}
134+
----
135+
136+
The PR will only be created if there is no open PR for the same branch, even if there is a newer version of Antora UI Spring.
137+
For example, if there is an open PR to update from version `v0.4.11` to `v0.4.12` and `v0.4.13` is released, the workflow won't open a new PR for `v0.4.13` if the previous one is not closed.

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

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

Comments
 (0)