-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Automatic Draft Release Creator
This implements automatic draft release creator reusable workflow. [See](coopnorge/engineering-github-actions#52) for more details. Resolves coopnorge/engineering-issues#325
- Loading branch information
1 parent
54a6823
commit 9d47c40
Showing
5 changed files
with
315 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name-template: "v$RESOLVED_VERSION" | ||
tag-template: "v$RESOLVED_VERSION" | ||
change-template: "- $TITLE (#$NUMBER) @$AUTHOR" | ||
change-title-escapes: '\<*_&' | ||
categories: | ||
- title: "🔥 BREAKING CHANGES" | ||
labels: | ||
- "breaking-change" | ||
- title: "🚀 Features" | ||
labels: | ||
- "enhancement" | ||
- title: "🐛 Bug Fixes" | ||
labels: | ||
- "bug-fix" | ||
- title: "👷 Chores" | ||
labels: | ||
- "chore" | ||
- title: "⚡️ Deprecations" | ||
labels: | ||
- "deprecation" | ||
- title: "⬆️ Dependencies Upgraded" | ||
labels: | ||
- "dependency" | ||
exclude-labels: | ||
- "skip-changelog" | ||
replacers: | ||
# https://github.com/release-drafter/release-drafter/issues/569#issuecomment-645938155 | ||
- search: '(?:and )?@dependabot(?:\[bot\])?,?' | ||
replace: "" | ||
version-resolver: | ||
major: | ||
labels: | ||
- "major" | ||
minor: | ||
labels: | ||
- "minor" | ||
patch: | ||
labels: | ||
- "patch" | ||
default: patch | ||
exclude-contributors: | ||
- "dependabot" | ||
autolabeler: | ||
# labels to help with version determination | ||
# if you want to play around with the regex here | ||
# I will suggest doing so on https://regex101.com/ | ||
# it provides good explanation what what the regex is doing | ||
# If that is not enough, ask chatgpt for help, | ||
# and then go back to playing with regex on regex101.com | ||
- label: "patch" | ||
title: | ||
# matches in format of "fix: ..." | ||
# or "fix(scope): ..." | ||
- "/^(?:fix|chore|docs|doc|refactor|test|deprecated)(?:\((?:[^)]+)\))?:\s.*/i" | ||
- label: "minor" | ||
title: | ||
# matches in format of "feat: ..." | ||
# or "feat(scope): ..." | ||
- "/^(?:feat|feature)(?:\((?:[^)]+)\))?:\s.*/i" | ||
- label: "major" | ||
title: | ||
# matches in format of "fix!: ..." | ||
# or "fix!(scope): ..." | ||
# or "fix(scope)!: ..." | ||
- "/^(?:feat|feature|fix|chore|docs|doc|refactor|test|deprecated)(?:!(?:\((?:[^)]+)\))|(?:\((?:[^)]+)\))!|!):\s.*/i" | ||
body: | ||
- "/BREAKING CHANGE:/" | ||
# labels to help with changelog grouping | ||
- label: "dependency" | ||
title: | ||
- "/^Bump/" # Dependency update PR by depandabot | ||
- label: "chore" | ||
title: | ||
- "/^(?:docs|doc|chore|refactor|test)(?:\((?:[^)]+)\))?:\s.*/i" | ||
- label: "enhancements" | ||
title: | ||
- "/^(?:feat|feature)(?:\((?:[^)]+)\))?:\s.*/i" | ||
- label: "bug-fix" | ||
title: | ||
- "/^fix(?:\((?:[^)]+)\))?:\s.*/i" | ||
- label: "deprecation" | ||
title: | ||
- "/^deprecated(?:\((?:[^)]+)\))?:\s.*/i" | ||
- label: "breaking-change" | ||
title: | ||
- "/^(?:feat|feature|fix|chore|docs|doc|refactor|test|deprecated)(?:!(?:\((?:[^)]+)\))|(?:\((?:[^)]+)\))!|!):\s.*/i" | ||
body: | ||
- "/BREAKING CHANGE:/" | ||
template: | | ||
## What's Changed | ||
$CHANGES |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
on: | ||
workflow_call: | ||
inputs: | ||
config-name: | ||
type: string | ||
description: >- | ||
Config filename. This should either be present in your repository's | ||
.github folder or .github repo's .github folder. | ||
required: false | ||
default: release-drafter.yml | ||
commitish: | ||
type: string | ||
description: >- | ||
Commitish to use when calculating the version bump. Defaults to the | ||
pull request base branch. | ||
required: false | ||
default: main | ||
publish: | ||
type: boolean | ||
description: Publish the release draft. Defaults to false. | ||
required: false | ||
default: false | ||
project-path: | ||
type: string | ||
description: The path to go project | ||
required: false | ||
default: . | ||
secrets: | ||
PERSONAL_ACCESS_TOKEN: | ||
required: true | ||
jobs: | ||
label-pr-go: | ||
if: github.event_name == 'pull_request' | ||
name: Label PR (Golang) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version-file: '${{ inputs.project-path }}/go.mod' | ||
- name: Install API DIff | ||
run: go install golang.org/x/exp/cmd/apidiff@latest | ||
- name: Get PR diff | ||
id: apidiff | ||
run: | | ||
cd ${{ inputs.project-path }} | ||
git diff --name-only origin/main HEAD | grep '\.go$' > changes.txt | ||
if [ -s changes.txt ]; then | ||
echo "Detected Go changes. Checking API diff..." | ||
apidiff -w new.txt . | ||
git checkout origin/main | ||
apidiff -w old.txt . | ||
DIFFERENCE=$(apidiff old.txt new.txt) | ||
if [ "$DIFFERENCE" != "" ]; then | ||
echo "API diff detected. $DIFFERENCE" | ||
if echo "$DIFFERENCE" | grep -q -i "incompatible change"; then | ||
echo "Incompatible API change detected." | ||
echo "semver-type=major" >> $GITHUB_OUTPUT | ||
elif echo "$DIFFERENCE" | grep -q -i "compatible change"; then | ||
echo "Compatible API change detected." | ||
echo "semver-type=minor" >> $GITHUB_OUTPUT | ||
else | ||
echo "Non-breaking API change detected." | ||
echo "semver-type=patch" >> $GITHUB_OUTPUT | ||
fi | ||
else | ||
echo "No API diff detected." | ||
echo "semver-type=patch" >> $GITHUB_OUTPUT | ||
fi | ||
else | ||
echo "No Go changes detected." | ||
echo "semver-type=patch" >> $GITHUB_OUTPUT | ||
fi | ||
- uses: actions/github-script@v6 | ||
if: github.event_name == 'pull_request' | ||
env: | ||
LABEL: '${{ steps.apidiff.outputs.semver-type }}' | ||
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | ||
with: | ||
script: | | ||
const { LABEL } = process.env; | ||
github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: [`${LABEL}`] | ||
}) | ||
draft-release: | ||
name: Draft Release | ||
uses: >- | ||
coopnorge/github-workflow-release-drafter/.github/workflows/release-drafter.yaml@5f4750d814e5a92e08484cf0dc28deb9eeb47583 | ||
secrets: | ||
PERSONAL_ACCESS_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | ||
with: | ||
config-name: '${{ inputs.config-name }}' | ||
commitish: '${{ inputs.commitish }}' | ||
publish: ${{ inputs.publish }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
on: | ||
workflow_call: | ||
inputs: | ||
config-name: | ||
type: string | ||
description: >- | ||
Config filename. This should either be present in your repository's | ||
.github folder or .github repo's .github folder. | ||
required: false | ||
default: release-drafter.yml | ||
commitish: | ||
type: string | ||
description: >- | ||
Commitish to use when calculating the version bump. Defaults to the | ||
pull request base branch. | ||
required: false | ||
default: main | ||
publish: | ||
type: boolean | ||
description: Publish the release draft. Defaults to false. | ||
required: false | ||
default: false | ||
secrets: | ||
PERSONAL_ACCESS_TOKEN: | ||
required: true | ||
jobs: | ||
update-release-draft: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: release-drafter/release-drafter@65c5fb495d1e69aa8c08a3317bc44ff8aabe9772 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | ||
with: | ||
commitish: '${{ inputs.commitish }}' | ||
config-name: '${{ inputs.config-name }}' | ||
publish: '${{ inputs.publish }}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,85 @@ | ||
# github-workflows-template | ||
# github-workflows-release-drafter | ||
|
||
Steps: | ||
This workflow will create a release draft based on the PRs merged since the last release. It will also create a changelog based on the PRs merged. | ||
|
||
1. update / rename `.github/workflows/example-workflow.yaml` | ||
2. A README describing | ||
* what the workflow does | ||
* which input variables | ||
* an example | ||
This workflow will also try to assign labels to PR based on the title of the PR. The labels is defined [here](.github/release-drafter.yml) | ||
|
||
## Usage | ||
|
||
1. Create a `.github/workflows/release-drafter.yaml` file in your repository | ||
```yaml | ||
name: Release Drafter | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: | ||
- opened | ||
- reopened | ||
- synchronize | ||
- edited | ||
permissions: | ||
contents: read | ||
jobs: | ||
release-draft: | ||
permissions: | ||
pull-requests: write | ||
contents: write | ||
uses: >- | ||
coopnorge/github-workflows-release-drafter/.github/workflows/release-drafter.yaml@main | ||
secrets: inherit | ||
``` | ||
2. Create a `.github/release-drafter.yml` file in your repository. | ||
Copy the [default configuration](.github/release-drafter.yml) and modify it to your needs. | ||
|
||
## How it works | ||
|
||
When a PR is created, this workflow will check the PR title and try to assign labels to the PR based on the title. If you do not agree with the labels assigned you can assign new labels yourself. | ||
|
||
Supported labels for version bumping (only one label is taken into account, in order): | ||
|
||
``` | ||
- "major" # bump X.0.0 | ||
- "minor" # bump 0.X.0 | ||
- "patch" # bump 0.0.X | ||
``` | ||
|
||
Supported labels to help with changelog grouping: | ||
|
||
``` | ||
- "dependency" | ||
- "chore" | ||
- "enhancements" | ||
- "bug-fix" | ||
- "deprecation" | ||
- "breaking-change" | ||
``` | ||
|
||
After you have merged the PR, the draft release will be created/updated. The draft release will be based on the PRs merged since the last release. The draft release will also contain a changelog based on the PRs merged. | ||
|
||
When you are ready to release, you can publish the release draft. This will create a new release and tag the release with the version number. | ||
|
||
## Configuration | ||
|
||
### release-drafter.yml | ||
|
||
Supported configuration options: | ||
|
||
| Option | Description| Required | Default | | ||
| :---: | :--- | :---: | :---: | | ||
| `config-name` | The name of the configuration file to use| `false` | `release-drafter.yml` | | ||
| `commitish` | Commitish to use when calculating the version bump. Defaults to the pull request base branch. | `false` | `main` | | ||
| `publish` | Publish the release draft when the PR is merged. | `false` | `false` | | ||
|
||
### release-drafter-go.yml | ||
|
||
Supported configuration options: | ||
|
||
| Option | Description| Required | Default | | ||
| :---: | :--- | :---: | :---: | | ||
| `config-name` | The name of the configuration file to use| `false` | `release-drafter.yml` | | ||
| `commitish` | Commitish to use when calculating the version bump. Defaults to the pull request base branch. | `false` | `main` | | ||
| `publish` | Publish the release draft when the PR is merged. | `false` | `false` | | ||
| `project-path` | The path to go project. | `false` | `.` | |