Skip to content
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

Add action to create a module release PR #66

Draft
wants to merge 1 commit into
base: v3
Choose a base branch
from
Draft
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
66 changes: 66 additions & 0 deletions .github/workflows/prepare_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---

name: Prepare Release

on:
workflow_call:
inputs:
version:
description: 'Module version to be released.'
required: true
Copy link
Member

Choose a reason for hiding this comment

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

I would love it if we had some logic to automatically detect this based on labels, making it optional but when I looked at it I had trouble coming up with a good solution so this is a good first step.

Copy link
Member Author

Choose a reason for hiding this comment

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

dito. I would also love to do this automatically. but one step at a time.

type: string
working-directory:
description: The working directory where all jobs should be executed. Used for modules in subdirectories like a monorepo or a control repository.
default: '.'
required: false
type: string
base-branch:
description: 'The branch that will be used as the origin for the release branch.'
required: false
default: 'master'
type: string

env:
BUNDLE_WITHOUT: development:test:system_tests
GIT_AUTHOR_NAME: Release Automation
GIT_AUTHOR_EMAIL: "${{ github.repository_owner }}@users.noreply.github.com"
bastelfreak marked this conversation as resolved.
Show resolved Hide resolved
BLACKSMITH_FULL_VERSION: "${{ inputs.version }}"

jobs:
prepare_release:
defaults:
run:
working-directory: ${{ inputs.working-directory }}
name: 'Puppet Forge'
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
Copy link
Member

Choose a reason for hiding this comment

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

With my yellow Foreman hat on: we maintain stable branches as well and if we need to create multiple release then it would be nice if there was a parameter for the base branch. Then you should also take that into account for the target branch name

Copy link
Member Author

Choose a reason for hiding this comment

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

updated it. it defaults to master now, but you can provide a different branch name as base for the release_prep branch / for the PR.

Copy link
Member

Choose a reason for hiding this comment

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

If you don't specify any default, it should just work regardless of the default branch.

with:
ref: ${{ inputs.base-branch }}
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.3'
bundler-cache: true
working-directory: ${{ inputs.working-directory }}
- name: Update metadata.json to new version
run: bundle exec rake module:bump:full
- name: Update CHANGELOG.md and update REFERENCE.md if required
env:
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication
CHANGELOG_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bundle exec rake release:prepare
- name: 'Check if a release is necessary'
id: 'check'
run: |
git diff --quiet CHANGELOG.md && echo "release=false" >> $GITHUB_OUTPUT || echo "release=true" >> $GITHUB_OUTPUT
bastelfreak marked this conversation as resolved.
Show resolved Hide resolved
- name: 'Commit changes'
if: ${{ steps.check.outputs.release == 'true' }}
env:
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Copy link
Member

Choose a reason for hiding this comment

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

One interesting side note: if that's the normal token GH generates on the fly when the action runs, the created PR will not trigger any further GH actions (like CI).

Reads docs https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#using-the-github_token-in-a-workflow

Oh, this is not the case for workflow dispatch, TIL

run: |
git switch --create release_prep
git commit --all --message="Release ${{ steps.get_version.outputs.version }}"
gh pr create --title "Release ${{ steps.get_version.outputs.version }}" --label skip-changelog --base ${{ inputs.base-branch }} --fill
Comment on lines +54 to +66
Copy link
Member

Choose a reason for hiding this comment

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

I can only recommend using peter-evans/create-pull-request instead of wrangling all those steps manually.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok ok!