From a267c7a2e8341e40607868776762154d6148568a Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Mon, 9 Oct 2023 14:17:04 +0200 Subject: [PATCH 01/14] feat: added callable workflow that creates a draft release on pr --- .github/release-drafter.yml | 61 ++++++++++++++++++++++++++ .github/workflows/release-drafter.yaml | 24 ++++++++++ 2 files changed, 85 insertions(+) create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/release-drafter.yaml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..45ae1e4 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,61 @@ +name-template: "v$RESOLVED_VERSION" +tag-template: "v$RESOLVED_VERSION" +change-template: "- $TITLE (#$NUMBER) @$AUTHOR" +categories: + - title: "Major Changes" + labels: + - "major" # c6476b + - title: "Minor Changes" + labels: + - "feature" + - "enhancement" + - "refactoring" + - title: "Bugfixes" + labels: + - "bug" + - title: "Deprecations" + labels: + - "deprecated" +exclude-labels: + - "bot:chronographer:skip" + - "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" + - "feature" + patch: + labels: + - "bug" + - "deprecated" + default: patch +exclude-contributors: + - "dependabot" +autolabeler: + - label: "skip-changelog" + title: + - "/autoupdate/" + - "/^chore/i" + - "/^doc/i" + - label: "bug" + title: + - "/^fix/i" + - label: "feature" + title: + - "/^feat/i" + - "/^feature/i" + - label: "deprecated" + title: + - "/^deprecate/i" + - labeld: "major" + body: + - "/BREAKING CHANGE:/" +template: | + $CHANGES \ No newline at end of file diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml new file mode 100644 index 0000000..12a7c26 --- /dev/null +++ b/.github/workflows/release-drafter.yaml @@ -0,0 +1,24 @@ +name: Release Drafter + +on: + workflow_call: + secrets: + GITHUB_TOKEN: + description: 'Token' + required: true + +permissions: + contents: read + +jobs: + update_release_draft: + permissions: + contents: write + pull-requests: write + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +# See: https://github.com/release-drafter/release-drafter \ No newline at end of file From da283090e4e87e9f74c89eac0627d961a2a9c080 Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Mon, 9 Oct 2023 14:25:21 +0200 Subject: [PATCH 02/14] docs: Updated README on how to use release-drafter workflow --- README.md | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 64837ec..dbfcf49 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,40 @@ # engineering-github-actions -Repository to store reusable workflows for github actions \ No newline at end of file +Repository to store reusable workflows for github actions + +## Workflows + +### [release-drafter.yml](./.github/workflows/release-drafter.yml) + +This workflow can be used to create a release draft based on the PRs merged since the last release. It will also create a changelog based on the PRs merged. + +To use: + +1. Create a `.github/workflows/release-drafter.yml` file in your repository +```yaml +name: Release Drafter + +on: + push: + branches: + - main + pull_request: + types: [open, reopened, synchronize] + +permissions: + contents: read + +jobs: + release-draft: + steps: + - uses: actions/checkout@v4 + - uses: coopnorge/engineering-github-actions/.github/workflows/release-drafter.yaml@main + secrets: inherit +``` + +2. Create a `.github/release-drafter.yml` file in your repository +```yaml +__extends: coopnorge/engineering-github-actions +``` + +Alternatively, I would would like to specify your own template for the release notes, you can do so by copying the [default template](https://github.com/coopnorge/engineering-github-actions/.github/release-drafter.yml) and modifying it to your needs. \ No newline at end of file From eda20985aa66c388adac4c84c32f79099486a41e Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Tue, 10 Oct 2023 08:59:32 +0200 Subject: [PATCH 03/14] set config-name to release_drafter.yml as that is what was committed to the test project --- .github/workflows/release-drafter.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml index 12a7c26..616245e 100644 --- a/.github/workflows/release-drafter.yaml +++ b/.github/workflows/release-drafter.yaml @@ -20,5 +20,7 @@ jobs: - uses: release-drafter/release-drafter@v5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + config-name: release_drafter.yml # See: https://github.com/release-drafter/release-drafter \ No newline at end of file From d9617d93077b3b79b54353c75b1c1121a25f0cb7 Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Tue, 10 Oct 2023 09:26:10 +0200 Subject: [PATCH 04/14] point commitish to main branch --- .github/workflows/release-drafter.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml index 616245e..8132472 100644 --- a/.github/workflows/release-drafter.yaml +++ b/.github/workflows/release-drafter.yaml @@ -22,5 +22,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: config-name: release_drafter.yml + commitish: main # See: https://github.com/release-drafter/release-drafter \ No newline at end of file From e213c9e83be54230b4e8b2f95481f8c703415328 Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Tue, 10 Oct 2023 09:49:46 +0200 Subject: [PATCH 05/14] fix: use default config-name docs: updated doc to point out that step 2 is optional --- .github/workflows/release-drafter.yaml | 1 - README.md | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml index 8132472..8a874e2 100644 --- a/.github/workflows/release-drafter.yaml +++ b/.github/workflows/release-drafter.yaml @@ -21,7 +21,6 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - config-name: release_drafter.yml commitish: main # See: https://github.com/release-drafter/release-drafter \ No newline at end of file diff --git a/README.md b/README.md index dbfcf49..bbd8231 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ jobs: secrets: inherit ``` -2. Create a `.github/release-drafter.yml` file in your repository +2. **OPTIONAL:** Create a `.github/release-drafter.yml` file in your repository ```yaml __extends: coopnorge/engineering-github-actions ``` From 625f1c5b3c82e07caa2581837eb972420b5c27fe Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Tue, 10 Oct 2023 12:27:39 +0200 Subject: [PATCH 06/14] chore: removed .github/release-drafter.yml `.github/release-drafter.yml` has been removed from this repo in favor of [this](https://github.com/coopnorge/.github/blob/main/.github/release-drafter.yml) --- .github/release-drafter.yml | 61 ------------------------------------- 1 file changed, 61 deletions(-) delete mode 100644 .github/release-drafter.yml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml deleted file mode 100644 index 45ae1e4..0000000 --- a/.github/release-drafter.yml +++ /dev/null @@ -1,61 +0,0 @@ -name-template: "v$RESOLVED_VERSION" -tag-template: "v$RESOLVED_VERSION" -change-template: "- $TITLE (#$NUMBER) @$AUTHOR" -categories: - - title: "Major Changes" - labels: - - "major" # c6476b - - title: "Minor Changes" - labels: - - "feature" - - "enhancement" - - "refactoring" - - title: "Bugfixes" - labels: - - "bug" - - title: "Deprecations" - labels: - - "deprecated" -exclude-labels: - - "bot:chronographer:skip" - - "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" - - "feature" - patch: - labels: - - "bug" - - "deprecated" - default: patch -exclude-contributors: - - "dependabot" -autolabeler: - - label: "skip-changelog" - title: - - "/autoupdate/" - - "/^chore/i" - - "/^doc/i" - - label: "bug" - title: - - "/^fix/i" - - label: "feature" - title: - - "/^feat/i" - - "/^feature/i" - - label: "deprecated" - title: - - "/^deprecate/i" - - labeld: "major" - body: - - "/BREAKING CHANGE:/" -template: | - $CHANGES \ No newline at end of file From 03b1ee416ef6656bf157d7d3cecb2572fa9e84a4 Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Tue, 10 Oct 2023 12:44:09 +0200 Subject: [PATCH 07/14] style: changed the jobid to kebab-case --- .github/workflows/release-drafter.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml index 8a874e2..6ba6783 100644 --- a/.github/workflows/release-drafter.yaml +++ b/.github/workflows/release-drafter.yaml @@ -11,7 +11,7 @@ permissions: contents: read jobs: - update_release_draft: + update-release-draft: permissions: contents: write pull-requests: write From 4cd0ba4c481124a80665bf80bb3d716c0c6b829d Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Tue, 10 Oct 2023 22:38:38 +0200 Subject: [PATCH 08/14] chore: removed unnessary permission and cleaned up secret requirements --- .github/workflows/release-drafter.yaml | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml index 6ba6783..85f532e 100644 --- a/.github/workflows/release-drafter.yaml +++ b/.github/workflows/release-drafter.yaml @@ -2,19 +2,9 @@ name: Release Drafter on: workflow_call: - secrets: - GITHUB_TOKEN: - description: 'Token' - required: true - -permissions: - contents: read jobs: update-release-draft: - permissions: - contents: write - pull-requests: write runs-on: ubuntu-latest steps: - uses: release-drafter/release-drafter@v5 From 2ae0109216767595368862efc04eda791d0f8b27 Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Tue, 10 Oct 2023 22:45:57 +0200 Subject: [PATCH 09/14] fix: token was required as it was cross repo workflow call --- .github/workflows/release-drafter.yaml | 4 +++ README.md | 37 ++++++++++++-------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.github/workflows/release-drafter.yaml b/.github/workflows/release-drafter.yaml index 85f532e..164eaea 100644 --- a/.github/workflows/release-drafter.yaml +++ b/.github/workflows/release-drafter.yaml @@ -2,6 +2,10 @@ name: Release Drafter on: workflow_call: + secrets: + GITHUB_TOKEN: + description: 'Token' + required: true jobs: update-release-draft: diff --git a/README.md b/README.md index bbd8231..716e083 100644 --- a/README.md +++ b/README.md @@ -6,35 +6,32 @@ Repository to store reusable workflows for github actions ### [release-drafter.yml](./.github/workflows/release-drafter.yml) -This workflow can be used to create a release draft based on the PRs merged since the last release. It will also create a changelog based on the PRs merged. +This workflow can be used to create a release draft based on the PRs since the last release. It will also create a changelog based on the PRs merged. To use: 1. Create a `.github/workflows/release-drafter.yml` file in your repository ```yaml name: Release Drafter - on: - push: - branches: - - main - pull_request: - types: [open, reopened, synchronize] - + push: + branches: + - main + pull_request: + types: + - open + - reopened + - synchronize permissions: - contents: read - + contents: read jobs: - release-draft: - steps: - - uses: actions/checkout@v4 - - uses: coopnorge/engineering-github-actions/.github/workflows/release-drafter.yaml@main - secrets: inherit + release-draft: + uses: >- + coopnorge/engineering-github-actions/.github/workflows/release-drafter.yaml@main + secrets: inherit ``` -2. **OPTIONAL:** Create a `.github/release-drafter.yml` file in your repository -```yaml -__extends: coopnorge/engineering-github-actions -``` +2. **OPTIONAL:** Create a `.github/release-drafter.yml` file in your repository. +Copy the [default configuration](https://github.com/coopnorge/.github/blob/main/.github/release-drafter.yml) and modify it to your needs. -Alternatively, I would would like to specify your own template for the release notes, you can do so by copying the [default template](https://github.com/coopnorge/engineering-github-actions/.github/release-drafter.yml) and modifying it to your needs. \ No newline at end of file +** NOTE: ** Although it is possible to have different format for release drafts. It is recommended to use the default format to ensure consistency across repositories. If you have any suggestion on how the release should look like please open an issue. \ No newline at end of file From 47fb7b6b8bdd57e6fbffde86b7d86e54cb48674c Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Tue, 10 Oct 2023 23:09:32 +0200 Subject: [PATCH 10/14] chore: added docs for release drafter --- .github/workflows/build.yaml | 21 ++++++++++++ catelog-info.yaml | 14 ++++++++ docs/index.md | 64 ++++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 .github/workflows/build.yaml create mode 100644 catelog-info.yaml create mode 100644 docs/index.md diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..1970146 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,21 @@ +--- +on: + pull_request: +jobs: + techdocs: + permissions: + contents: read + id-token: write + packages: read + name: TechDocs + uses: coopnorge/github-workflow-techdocs/.github/workflows/techdocs.yaml@v0 + + build: + if: always() + needs: + - techdocs + runs-on: ubuntu-latest + steps: + - run: exit 1 + if: | + needs.techdocs.result == 'failure' \ No newline at end of file diff --git a/catelog-info.yaml b/catelog-info.yaml new file mode 100644 index 0000000..29d30d4 --- /dev/null +++ b/catelog-info.yaml @@ -0,0 +1,14 @@ +apiVersion: backstage.io/v1alpha1 +kind: Component +metadata: + name: engineering-github-action-release-drafter + title: Create draft releases from pull requests + description: | + Create draft releases from pull requests + annotations: + github.com/project-slug: coopnorge/engineering-github-action + backstage.io/techdocs-ref: dir:. +spec: + type: library + lifecycle: production + owner: engineering \ No newline at end of file diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 0000000..02a97e8 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,64 @@ +# Github workflow to create a release draft based on the PRs since the last release (release-drafter.yaml) + +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. + +This workflow will also try to assign labels to PR based on the title of the PR. The labels is defined [here](https://github.com/coopnorge/.github/blob/main/.github/release-drafter.yml) + +## Usage + +1. Create a `.github/workflows/release-drafter.yml` 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/engineering-github-actions/.github/workflows/release-drafter.yaml@main + secrets: inherit +``` + +2. **OPTIONAL:** Create a `.github/release-drafter.yml` file in your repository. +Copy the [default configuration](https://github.com/coopnorge/.github/blob/main/.github/release-drafter.yml) and modify it to your needs. + +** NOTE: ** Although it is possible to have different format for release drafts. It is recommended to use the default format to ensure consistency across repositories. If you have any suggestion on how the release should look like please open an issue. + +## 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: + +``` +- "patch" # bump 0.0.X +- "minor" # bump 0.X.0 +- "major" # bump X.0.0 +``` + +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. \ No newline at end of file From 87297c7072134290283e491556706486bccff678 Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Wed, 11 Oct 2023 09:15:34 +0200 Subject: [PATCH 11/14] chore: changed lifecycle on catalog to experimental --- catelog-info.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catelog-info.yaml b/catelog-info.yaml index 29d30d4..4250f11 100644 --- a/catelog-info.yaml +++ b/catelog-info.yaml @@ -10,5 +10,5 @@ metadata: backstage.io/techdocs-ref: dir:. spec: type: library - lifecycle: production + lifecycle: experimental owner: engineering \ No newline at end of file From 39c38fc3f0af1437c0d08d853f3380142022f85e Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Wed, 11 Oct 2023 09:22:51 +0200 Subject: [PATCH 12/14] fix: fixed typo in catalog-info filename --- catelog-info.yaml => catalog-info.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename catelog-info.yaml => catalog-info.yaml (100%) diff --git a/catelog-info.yaml b/catalog-info.yaml similarity index 100% rename from catelog-info.yaml rename to catalog-info.yaml From 1dd9dca709d3b79f9f61604340b2d17923183831 Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Wed, 11 Oct 2023 09:25:15 +0200 Subject: [PATCH 13/14] fix: removed techdoc build for now as it was failing --- .github/workflows/build.yaml | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 .github/workflows/build.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index 1970146..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,21 +0,0 @@ ---- -on: - pull_request: -jobs: - techdocs: - permissions: - contents: read - id-token: write - packages: read - name: TechDocs - uses: coopnorge/github-workflow-techdocs/.github/workflows/techdocs.yaml@v0 - - build: - if: always() - needs: - - techdocs - runs-on: ubuntu-latest - steps: - - run: exit 1 - if: | - needs.techdocs.result == 'failure' \ No newline at end of file From af297e3c0bab98038f28f62357d12027bce2668d Mon Sep 17 00:00:00 2001 From: Arun Poudel Date: Wed, 11 Oct 2023 10:18:34 +0200 Subject: [PATCH 14/14] docs: fixed sample snippet in README (feedback Bendik) --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 716e083..57e80a9 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,17 @@ on: - main pull_request: types: - - open + - opened - reopened - synchronize + - edited permissions: contents: read jobs: release-draft: + permissions: + pull-requests: write + contents: write uses: >- coopnorge/engineering-github-actions/.github/workflows/release-drafter.yaml@main secrets: inherit