Skip to content

Create update-antora-ui-spring action #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,52 @@ Example usage:
docs-ssh-host-key: ${{ secrets.DOCS_SSH_HOST_KEY }}
dry-run: true
----

== update-antora-ui-spring

A GitHub Action that detects if there is a new version of the Antora UI Spring artifact and creates a PR to update it.

[source,yml]
----
inputs:
docs-branch:
description: The branch where the file containing the Antora UI Spring artifact is. Default is 'docs-build'
default: 'docs-build'
workflow-branch-suffix:
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
default: 'update-antora-ui-spring'
antora-file-path:
description: Path to the Antora file containing the Antora UI Spring artifact. Default is 'antora-playbook.yml'.
default: 'antora-playbook.yml'
token:
description: Token with write permission to pull-requests, issues and contents
required: true
----

Example usage:

.github/workflows/update-antora-ui-spring.yml
[source,yml,subs=attributes+]
----
permissions:
pull-requests: write
issues: write
contents: write

jobs:
update-antora-ui-spring:
runs-on: ubuntu-latest
name: Update Antora UI Spring
strategy:
matrix:
branch: ['main', 'docs-build']
steps:
- uses: spring-io/spring-docs-actions/update-antora-spring-ui@{ACTION_VERSION}
name: Update antora-playbook.yml
with:
docs-branch: ${{ matrix.branch }}
token: ${{ secrets.GITHUB_TOKEN }}
----

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.
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.
100 changes: 100 additions & 0 deletions update-antora-spring-ui/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Update Antora UI Spring
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.

inputs:
docs-branch:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is helpful to update the docs-build branch, but we should consider that we should also be able to send PRs for the currently active branches (e.g. main, 6.2.x, etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added to the README how to make it run for multiple branches:

jobs:
  update-antora-ui-spring:
    runs-on: ubuntu-latest
    name: Update Antora UI Spring
    strategy:
      matrix:
        branch: ['main', 'docs-build']
    steps:
      - uses: spring-io/spring-docs-actions/update-antora-spring-ui@{ACTION_VERSION}
        name: Update antora-playbook.yml
        with:
          docs-branch: ${{ matrix.branch }}
          token: ${{ secrets.GITHUB_TOKEN }}

description: The branch where the file containing the Antora UI Spring artifact is. Default is 'docs-build'
default: 'docs-build'
workflow-branch-suffix:
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
default: 'update-antora-ui-spring'
antora-file-path:
description: Path to the Antora file containing the Antora UI Spring artifact. Default is 'antora-playbook.yml'.
default: 'antora-playbook.yml'
token:
description: Token with write permission to pull-requests, issues and contents
required: true

runs:
using: "composite"
steps:
- uses: actions/checkout@v4
- id: generate-branch-name
name: Generate Branch Name
run: echo "branch-name=${{ inputs.docs-branch }}_${{ inputs.workflow-branch-suffix }}" >> $GITHUB_OUTPUT
shell: bash
- id: check-existing-pr
name: Check for Existing PR
run: |
pr_count=$(gh pr list --head ${{ steps.generate-branch-name.outputs.branch-name }} --base ${{ inputs.docs-branch }} --state open --json id | jq length)
if [[ $pr_count -eq 0 ]]; then
echo "continue=true" >> $GITHUB_OUTPUT
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want it to stop if there is an existing PR? What happens if a PR is created for version 0.0.1 and then a newer version of the UI becomes available? Should we perhaps update the existing PR in that case?

At minimum, I think we should document (in the README) what happens when a PR already exists. We should also document how to get it to create a PR for the latest version (e.g. close the PR and delete the branch). It would be valuable to echo out that it is not continuing looking for a newer version and why with a link to the section of the README too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added to the README what happens when there is an open PR

else
echo "Found at least one open PR, won't make any changes until the PR is closed."
fi
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
- name: Delete Existing Branch If No PR Open
if: ${{ steps.check-existing-pr.outputs.continue == 'true' }}
run: |
if git ls-remote --exit-code --heads origin "${{ steps.generate-branch-name.outputs.branch-name }}" >/dev/null 2>&1; then
echo "Deleting ${{ steps.generate-branch-name.outputs.branch-name }} branch"
git push -d origin ${{ steps.generate-branch-name.outputs.branch-name }}
fi
shell: bash
- name: Get Current UI Bundle URL
id: current
if: ${{ steps.check-existing-pr.outputs.continue == 'true' }}
run: |
echo current_ui_bundle_url=$(grep -oE 'http[s]?://[^ ]+/ui-bundle.zip' -i -w ${{ inputs.antora-file-path }}) >> $GITHUB_OUTPUT
shell: bash
- name: Get Latest UI Bundle URL
id: latest
if: ${{ steps.check-existing-pr.outputs.continue == 'true' }}
run: |
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
echo tag_name=$(gh api /repos/spring-io/antora-ui-spring/releases/latest | jq -r '.tag_name') >> $GITHUB_OUTPUT
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
- name: Replace Current with Latest
id: replace
if: ${{ steps.current.outputs.current_ui_bundle_url != steps.latest.outputs.latest_ui_bundle_url }}
run: |
sed -i 's@${{ steps.current.outputs.current_ui_bundle_url }}@${{ steps.latest.outputs.latest_ui_bundle_url }}@g' ${{ inputs.antora-file-path }}
shell: bash
- name: Setup Git User
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
shell: bash
- name: Create Commit
id: commit
run: |
if [ "$(git status --porcelain)" ]; then
git switch -c ${{ steps.generate-branch-name.outputs.branch-name }}
git add .
git commit -m "Update Antora Spring UI to ${{ steps.latest.outputs.tag_name }}"
git push origin ${{ steps.generate-branch-name.outputs.branch-name }}
echo create_pr=true >> $GITHUB_OUTPUT
else
echo "No changes detected, will not create a commit"
echo create_pr=false >> $GITHUB_OUTPUT
fi
shell: bash
- name: Create Pull Request
if: ${{ steps.commit.outputs.create_pr == 'true' }}
id: pull_request
uses: actions/github-script@v7
with:
script: |
const { repo, owner } = context.repo;
await github.rest.pulls.create({
title: 'Update Antora UI Spring to ${{ steps.latest.outputs.tag_name }}',
owner: owner,
repo: repo,
head: '${{ steps.generate-branch-name.outputs.branch-name }}',
base: '${{ inputs.docs-branch }}',
});

Loading