From b6d71aeb3e913af7261e62c9091802078f6cb6b5 Mon Sep 17 00:00:00 2001 From: Le Minh Tri Date: Sun, 12 Feb 2023 14:31:40 +0700 Subject: [PATCH 1/6] ci(github-actions): add worflow release --- .github/workflows/release.yaml | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..3171460 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,67 @@ +name: release + +on: + pull_request: + branches: + - main + types: + - closed + +env: + BRANCH_MAIN: main + BRANCH_DEVELOP: develop + +jobs: + release: + name: Publish new release + runs-on: ubuntu-latest + permissions: + contents: write + # only merge pull requests that begin with 'release/' or 'hotfix/' + if: github.event.pull_request.merged == true && + (startsWith(github.event.pull_request.head.ref, 'release/') || startsWith(github.event.pull_request.head.ref, 'hotfix/')) + + steps: + - name: Extract version from release branch + if: startsWith(github.event.pull_request.head.ref, 'release/') + run: | + BRANCH_NAME="${{ github.event.pull_request.head.ref }}" + VERSION=${BRANCH_NAME#release/} + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV + + - name: Extract version from hotfix branch + if: startsWith(github.event.pull_request.head.ref, 'hotfix/') + run: | + BRANCH_NAME="${{ github.event.pull_request.head.ref }}" + VERSION=${BRANCH_NAME#hotfix/} + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV + + - name: Create release + uses: ncipollo/release-action@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit: ${{ github.event.pull_request.merge_commit_sha }} + tag: ${{ env.RELEASE_VERSION }} + name: ${{ env.RELEASE_VERSION }} + draft: false + prerelease: false + generateReleaseNotes: true + + - name: Create merge PR ${{ github.event.pull_request.head.ref }} -> ${{ env.BRANCH_DEVELOP }} + uses: peter-evans/create-pull-request@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + base: ${{ env.BRANCH_DEVELOP }} + branch: ${{ github.event.pull_request.head.ref }} + delete-branch: false + commit-message: Merge branch '${{ github.event.pull_request.head.ref }}' into ${{ env.BRANCH_DEVELOP }} + title: Merge branch '${{ github.event.pull_request.head.ref }}' into ${{ env.BRANCH_DEVELOP }} + body: | + This PR merges the ${{ github.event.pull_request.head.ref }} branch back into ${{ env.BRANCH_DEVELOP }} branch. + This happens to ensure that the updates that happened on the ${{ github.event.pull_request.head.ref }} branch, i.e. CHANGELOG and manifest updates are also present on the ${{ env.BRANCH_DEVELOP }} branch. + + Auto-generated by [create-pull-request][1] + + [1]: https://github.com/peter-evans/create-pull-request + labels: | + automated-pr From 49cba32fbba5f38d9ad0d79083e95835c8e46620 Mon Sep 17 00:00:00 2001 From: Le Minh Tri Date: Sun, 12 Feb 2023 14:31:53 +0700 Subject: [PATCH 2/6] docs: update README.md --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b81797e --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# sample-gitflow-release-workflows + +Sample Gitflow release workflow using GitHub Actions. + +## Manual + +- Workflow definitions: [release.yaml](./.github/workflows/release.yaml) +- You have to update two env variables: `BRANCH_MAIN`, `BRANCH_DEVELOP` if necessary. + +## License + +This source code is available under the [MIT License](/LICENSE). From 5da410ee04fe1151835df35f4795dab51d18aa18 Mon Sep 17 00:00:00 2001 From: Le Minh Tri Date: Sun, 12 Feb 2023 14:58:00 +0700 Subject: [PATCH 3/6] fix(github-actions): rename repository secret variable GITHUB_TOKEN to GH_TOKEN --- .github/workflows/release.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 3171460..51615fe 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -39,7 +39,7 @@ jobs: - name: Create release uses: ncipollo/release-action@v1 with: - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.GH_TOKEN }} commit: ${{ github.event.pull_request.merge_commit_sha }} tag: ${{ env.RELEASE_VERSION }} name: ${{ env.RELEASE_VERSION }} @@ -50,7 +50,7 @@ jobs: - name: Create merge PR ${{ github.event.pull_request.head.ref }} -> ${{ env.BRANCH_DEVELOP }} uses: peter-evans/create-pull-request@v4 with: - token: ${{ secrets.GITHUB_TOKEN }} + token: ${{ secrets.GH_TOKEN }} base: ${{ env.BRANCH_DEVELOP }} branch: ${{ github.event.pull_request.head.ref }} delete-branch: false From a1fff5072c7eff47b5c93819c864292262e1fc16 Mon Sep 17 00:00:00 2001 From: Le Minh Tri Date: Sun, 12 Feb 2023 14:39:55 +0700 Subject: [PATCH 4/6] chore(release): 1.0.1-rc.0 --- CHANGELOG.md | 9 +++++++++ VERSION | 1 + 2 files changed, 10 insertions(+) create mode 100644 CHANGELOG.md create mode 100644 VERSION diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..056ea6e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changelog + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +### 1.0.1-rc.0 (2023-02-12) + +### Features + +* **ci:** add workflow release ([b6d71ae](https://github.com/ansidev/sample-gitflow-release-workflows/commit/b6d71aeb3e913af7261e62c9091802078f6cb6b5)) diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..3b70426 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.0.0-rc.1 \ No newline at end of file From d46d2c0d4fcde955b68d40400d51a33747a73016 Mon Sep 17 00:00:00 2001 From: Le Minh Tri Date: Mon, 13 Feb 2023 04:23:55 +0700 Subject: [PATCH 5/6] feat(github-actions): update workflow using GitHub CLI --- .github/workflows/release.yaml | 49 ++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 51615fe..201822a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,6 +10,7 @@ on: env: BRANCH_MAIN: main BRANCH_DEVELOP: develop + TAG_PREFIX: v jobs: release: @@ -36,32 +37,34 @@ jobs: VERSION=${BRANCH_NAME#hotfix/} echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV + - name: Set GitHub CLI token + run: | + echo "GH_TOKEN=${{ secrets.GH_TOKEN }}" >> $GITHUB_ENV + - name: Create release - uses: ncipollo/release-action@v1 - with: - token: ${{ secrets.GH_TOKEN }} - commit: ${{ github.event.pull_request.merge_commit_sha }} - tag: ${{ env.RELEASE_VERSION }} - name: ${{ env.RELEASE_VERSION }} - draft: false - prerelease: false - generateReleaseNotes: true + env: + RELEASE_TAG="${{ env.TAG_PREFIX }}${{ env.RELEASE_VERSION }}" + run: | + gh release create \ + ${{ env.RELEASE_TAG }} \ + --target ${{ github.event.pull_request.merge_commit_sha }} \ + --title "${{ env.RELEASE_TAG }}" \ + --generate-notes - name: Create merge PR ${{ github.event.pull_request.head.ref }} -> ${{ env.BRANCH_DEVELOP }} - uses: peter-evans/create-pull-request@v4 - with: - token: ${{ secrets.GH_TOKEN }} - base: ${{ env.BRANCH_DEVELOP }} - branch: ${{ github.event.pull_request.head.ref }} - delete-branch: false - commit-message: Merge branch '${{ github.event.pull_request.head.ref }}' into ${{ env.BRANCH_DEVELOP }} - title: Merge branch '${{ github.event.pull_request.head.ref }}' into ${{ env.BRANCH_DEVELOP }} - body: | + env: + PR_TITLE: Merge branch '${{ github.event.pull_request.head.ref }}' into ${{ env.BRANCH_DEVELOP }} + PR_BODY: | This PR merges the ${{ github.event.pull_request.head.ref }} branch back into ${{ env.BRANCH_DEVELOP }} branch. This happens to ensure that the updates that happened on the ${{ github.event.pull_request.head.ref }} branch, i.e. CHANGELOG and manifest updates are also present on the ${{ env.BRANCH_DEVELOP }} branch. - - Auto-generated by [create-pull-request][1] - - [1]: https://github.com/peter-evans/create-pull-request - labels: | + PR_LABELS: | automated-pr + run: | + gh pr create \ + --base ${{ env.BRANCH_DEVELOP }} \ + --head ${{ github.event.pull_request.head.ref }} \ + --target ${{ github.event.pull_request.merge_commit_sha }} \ + --title "${{ env.PR_TITLE }}" \ + --body "${{ env.PR_BODY }}" \ + --label "${{ env.PR_LABEL }}" \ + --fill From c5f20129416a39526b631a831eb94d3aacf040f5 Mon Sep 17 00:00:00 2001 From: Le Minh Tri Date: Mon, 13 Feb 2023 04:36:48 +0700 Subject: [PATCH 6/6] chore(release): 1.0.1-rc.0 --- .gitignore | 1 + .versionrc | 8 ++++++++ CHANGELOG.md | 12 ++++++++++++ VERSION | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .versionrc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d7bb2d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Taskfile.yaml diff --git a/.versionrc b/.versionrc new file mode 100644 index 0000000..8383dd3 --- /dev/null +++ b/.versionrc @@ -0,0 +1,8 @@ +{ + "bumpFiles": [ + { + "filename": "VERSION", + "type": "plain-text" + } + ] +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 056ea6e..10e20c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,18 @@ All notable changes to this project will be documented in this file. See [standa ### 1.0.1-rc.0 (2023-02-12) + +### Features + +* **github-actions:** update workflow using GitHub CLI ([d46d2c0](https://github.com/ansidev/sample-gitflow-release-workflows/commit/d46d2c0d4fcde955b68d40400d51a33747a73016)) + + +### Bug Fixes + +* **github-actions:** rename repository secret variable GITHUB_TOKEN to GH_TOKEN ([5da410e](https://github.com/ansidev/sample-gitflow-release-workflows/commit/5da410ee04fe1151835df35f4795dab51d18aa18)) + +### 1.0.0-rc.1 (2023-02-12) + ### Features * **ci:** add workflow release ([b6d71ae](https://github.com/ansidev/sample-gitflow-release-workflows/commit/b6d71aeb3e913af7261e62c9091802078f6cb6b5)) diff --git a/VERSION b/VERSION index 3b70426..878c965 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0-rc.1 \ No newline at end of file +1.0.1-rc.0 \ No newline at end of file