diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml new file mode 100644 index 0000000..dd451c2 --- /dev/null +++ b/.github/workflows/release-please.yml @@ -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 }} diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 717c315..48c8a9a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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) diff --git a/README.md b/README.md index 77aa936..e0f542d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/changelogs/dev-changelog.md b/changelogs/dev-changelog.md new file mode 100644 index 0000000..e46d777 --- /dev/null +++ b/changelogs/dev-changelog.md @@ -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 diff --git a/galaxy.yml b/galaxy.yml index 2847467..dee5f81 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -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) diff --git a/plugins/module_utils/version.py b/plugins/module_utils/version.py index 02caa36..b84aa2d 100644 --- a/plugins/module_utils/version.py +++ b/plugins/module_utils/version.py @@ -1 +1 @@ -version = "2.1.1" +version = "2.1.1" # x-release-please-version diff --git a/scripts/version-sync.sh b/scripts/version-sync.sh deleted file mode 100755 index 988f153..0000000 --- a/scripts/version-sync.sh +++ /dev/null @@ -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