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

feat: Automatic Draft Release Creator #2

Merged
merged 2 commits into from
Oct 16, 2023
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
91 changes: 91 additions & 0 deletions .github/release-drafter.yml
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
13 changes: 0 additions & 13 deletions .github/workflows/example-workflow.yaml

This file was deleted.

105 changes: 105 additions & 0 deletions .github/workflows/release-drafter-go.yaml
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 }}
36 changes: 36 additions & 0 deletions .github/workflows/release-drafter.yaml
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 }}'
92 changes: 85 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,87 @@
# 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@9d47c40559c78b2e314357fd99a5eca428eb5481
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.

**NOTE:** For golang project(`release-drafter-go.yaml`), the workflow try to check if exported interfaces are compatible or not using, [apidiff](https://pkg.go.dev/golang.org/x/exp/cmd/apidiff). If any exported interfaces is not compatible, the workflow will add a label `major` to the PR. If all exported interfaces are compatible, the workflow will add a label `minor` to the PR. And if there are no changes to exported interfaces, the workflow will add a label `patch` to the PR.

## 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` | `.` |
Loading