ci: setup release-please (#317)

##### SUMMARY

The current release process for this project requires multiple manual
local steps to prepare and then tag the release. This introduces the
standard release-please workflow we have in most of our integrations.

Release-please will open a new PR whenever there is a releasable change
and it updates the CHANGELOG & other files automatically in this PR.
Once the PR is merged a new tag is created.

This repository has some additional complexity as it uses
`antsibull-changelog` to maintain the user-facing changelog. This is
implemented ina second job in the `release-please` workflow which
executes when the release-please PR is updated and then runs
`antsibull-changelog release` against the version. The resulting changes
are pushed as a second commit to the same PR.
This commit is contained in:
Julian Tölle 2023-09-05 14:49:05 +02:00 committed by GitHub
parent 0f057b185f
commit eb4114bad3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 45 deletions

77
.github/workflows/release-please.yml vendored Normal file
View file

@ -0,0 +1,77 @@
on:
push:
branches:
- main
name: release-please
jobs:
release-please:
# The secret HCLOUD_BOT_TOKEN is only available on the main repo, not in forks.
if: github.repository == 'ansible-collections/hetzner.hcloud'
runs-on: ubuntu-latest
outputs:
pr-updated: ${{ steps.outputs.outputs.pr-updated }}
branch: ${{ steps.outputs.outputs.branch }}
version: ${{ steps.outputs.outputs.version }}
steps:
- id: release
uses: google-github-actions/release-please-action@v3
with:
token: ${{ secrets.HCLOUD_BOT_TOKEN }}
release-type: simple
package-name: hetzner.hcloud
# We use antsibull-changelog for the actual user-facing changelog.
changelog-path: changelogs/dev-changelog.md
extra-files: |
galaxy.yml
plugins/module_utils/version.py
- name: Prepare outputs
id: outputs
if: steps.release.outputs.pr != ''
run: |
echo "pr-updated=true" >> "$GITHUB_OUTPUT"
echo "branch=${{ fromJSON(steps.release.outputs.pr).headBranchName }}" >> "$GITHUB_OUTPUT"
echo "version=$(echo "${{ fromJSON(steps.release.outputs.pr).title }}" | awk '{print $3}')" >> "$GITHUB_OUTPUT"
antsibull-changelog:
runs-on: ubuntu-latest
needs: [release-please]
if: needs.release-please.outputs.pr-updated
steps:
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Install dependencies
run: pip install antsibull-changelog
- uses: actions/checkout@v3
with:
ref: ${{ needs.release-please.outputs.branch }}
- name: antsibull-changelog
run: antsibull-changelog release --version "${{ needs.release-please.outputs.version }}"
- name: Check for diff
id: antsibull-diff
run: |
if [[ $(git status --porcelain) ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
- name: Commit & Push
if: ${{ steps.antsibull-diff.outputs.changed }}
run: |
git config user.name "Hetzner Cloud Bot"
git config user.email "45457231+hcloud-bot@users.noreply.github.com"
git add changelogs/ CHANGELOG.rst
git commit -m "chore(main): changelog for version ${{ needs.release-please.outputs.version }}"
git push origin ${{ needs.release-please.outputs.branch }}

View file

@ -98,11 +98,3 @@ repos:
entry: scripts/integration-test-files.sh
pass_filenames: false
files: ^(scripts/integration-test-files.sh$|tests/integration)
- id: check-version-variables
name: check version variables
description: Ensure the version variables are in sync
language: system
entry: scripts/version-sync.sh
pass_filenames: false
files: ^(scripts/version-sync.sh$|galaxy.yml|plugins/module_utils/version.py)

View file

@ -61,31 +61,4 @@ ansible-test integration --color --local -vvv hcloud_server // Executed all int
## Releasing a new version
1. Make sure your local `main` branch is in a clean state and is up to date.
2. Define a new version:
```sh
export HCLOUD_VERSION=1.15.0
```
3. Create a release branch:
```sh
git checkout -b "release-$HCLOUD_VERSION"
```
4. Generate the changelog for the new version, it should remove all fragments and change
the `changelogs/changelog.yaml` and `CHANGELOG.rst`:
```sh
antsibull-changelog release --version "$HCLOUD_VERSION"
git add changelogs/changelog.yaml changelogs/fragments CHANGELOG.rst
```
5. Update the `version` in the ansible galaxy metadata file:
```sh
sed -i "s/^version: .*/version: $HCLOUD_VERSION/" galaxy.yml
scripts/version-sync.sh
git add galaxy.yml plugins/module_utils/version.py
```
6. Commit the changes:
```sh
git commit -m "chore: prepare v$HCLOUD_VERSION"
```
7. Push the changes to Github, open a Pull Request and follow the process to get the PR merged into `main`.
8. Once the PR is merged, tag the release through the Github UI, after this the Github Actions will run and publish the collection to Ansible
Galaxy.
If there are releasable changes, `release-please` will open a PR on GitHub with the proposed version. When this PR is merged, `release-please` will tag the release.

View file

@ -0,0 +1,8 @@
# Dev Changelog
> [!WARNING]
> For the user changelog, please check out [CHANGELOG.rst](../CHANGELOG.rst) instead.
This file contains a list of changes intended towards developers. It is auto-generated by release-please.
We would prefer to not generate this file, but disabling this is not supported currently: https://github.com/googleapis/release-please/issues/2007

View file

@ -1,6 +1,6 @@
namespace: hetzner
name: hcloud
version: 2.1.1
version: 2.1.1 # x-release-please-version
readme: README.md
authors:
- Hetzner Cloud (github.com/hetznercloud)

View file

@ -1 +1 @@
version = "2.1.1"
version = "2.1.1" # x-release-please-version

View file

@ -1,7 +0,0 @@
#!/usr/bin/env bash
# Sync the collection version variable based on the version in the galaxy.yml file.
galaxy_version="$(grep '^version:' galaxy.yml | cut -d ' ' -f 2)"
sed --in-place "s|version = .*|version = \"$galaxy_version\"|" plugins/module_utils/version.py