Skip to content

Commit 661bf19

Browse files
authored
Merge pull request #36 from btnguyen2k/release
Merge to main after releasing new version 0.1.0
2 parents e3a96a7 + bc036ca commit 661bf19

File tree

4 files changed

+119
-119
lines changed

4 files changed

+119
-119
lines changed

.github/workflows/ci.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
name: "ci"
1+
name: 'ci'
22

33
on:
44
push:
55
branches: [ '*' ]
6+
pull_request:
7+
types: [ opened, edited, reopened, synchronize, review_requested ]
8+
branches: [ '*' ]
69
workflow_call:
710

811
jobs:

.github/workflows/release.yaml

Lines changed: 84 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Automatically release a new version when a PR is merged to branch `release`
22

3-
name: "release"
3+
name: 'release'
44
on:
55
pull_request:
66
types: [ closed ]
7-
branches: [ release, main, dev ]
7+
branches: [ release ]
88

99
env:
1010
BRANCH_TO_RELEASE: 'release'
@@ -17,31 +17,13 @@ jobs:
1717
ReleaseDryRun:
1818
runs-on: ubuntu-latest
1919
needs: [ CallCI ]
20+
if: |
21+
github.event.pull_request.merged == true
2022
outputs:
2123
RESULT: ${{ steps.release_dry_run.outputs.result }}
2224
VERSION: ${{ steps.release_dry_run.outputs.releaseVersion }}
2325
RELEASE_NOTES: ${{ steps.release_dry_run.outputs.releaseNotes }}
2426
steps:
25-
- name: Dummy 1
26-
run: |
27-
echo "BRANCH_TO_RELEASE: ${BRANCH_TO_RELEASE}"
28-
echo "GITHUB_REF: ${GITHUB_REF}"
29-
echo "TAG_PREFIX: ${TAG_PREFIX}"
30-
echo "github.event.workflow_run.event: ${{ github.event.workflow_run.event }}"
31-
echo "github.event.workflow_run.conclusion: ${{ github.event.workflow_run.conclusion }}"
32-
echo "github.event.pull_request: ${{ github.event.pull_request }}"
33-
echo "github.event: ${{ github.event }}"
34-
echo "github: ${{ github }}"
35-
- name: Dummy 2
36-
uses: actions/github-script@v7
37-
with:
38-
github-token: ${{ secrets.GITHUB_TOKEN }}
39-
script: |
40-
console.log(context.payload)
41-
# console.log(context.payload.workflow_run)
42-
# if (context.payload.workflow_run.event == 'pull_request') {
43-
# console.log(context.payload.pull_request)
44-
# }
4527
- name: Check out code
4628
uses: actions/checkout@v4
4729
- name: Install Node
@@ -61,91 +43,85 @@ jobs:
6143
tag-prefix: ${{ env.TAG_PREFIX }}
6244
tag-only: true
6345

64-
# Release:
65-
# runs-on: ubuntu-latest
66-
# if: |
67-
# github.event.workflow_run.event == 'pull_request' &&
68-
# github.event.workflow_run.conclusion == 'success' &&
69-
# github.event.pull_request.merged == true
70-
# needs: [ 'ReleaseDryRun' ]
71-
# permissions:
72-
# contents: write # to be able to publish a GitHub release
73-
# outputs:
74-
# RESULT: ${{ needs.ReleaseDryRun.outputs.RESULT }}
75-
# VERSION: ${{ needs.ReleaseDryRun.outputs.VERSION }}
76-
# RELEASE_NOTES: ${{ needs.ReleaseDryRun.outputs.RELEASE_NOTES }}
77-
# steps:
78-
# - name: Update module meta
79-
# run: |
80-
# RESULT='${{ needs.ReleaseDryRun.outputs.RESULT }}'
81-
# VERSION='${{ needs.ReleaseDryRun.outputs.VERSION }}'
82-
# RELEASE_NOTES='${{ needs.ReleaseDryRun.outputs.RELEASE_NOTES }}'
83-
#
84-
# echo "🕘 Updating module meta..."
85-
# echo " - RESULT: ${RESULT}"
86-
# echo " - VERSION: ${VERSION}"
87-
# echo " - RELEASE_NOTES: ${RELEASE_NOTES}"
88-
# if [ "${RESULT}" == "SUCCESS" ]; then
89-
# echo "✅ Done."
90-
# else
91-
# echo "❎ SKIPPED."
92-
# fi
46+
Release:
47+
runs-on: ubuntu-latest
48+
if: |
49+
github.event.pull_request.merged == true
50+
needs: [ ReleaseDryRun ]
51+
permissions:
52+
contents: write # to be able to publish a GitHub release
53+
outputs:
54+
RESULT: ${{ needs.ReleaseDryRun.outputs.RESULT }}
55+
VERSION: ${{ needs.ReleaseDryRun.outputs.VERSION }}
56+
RELEASE_NOTES: ${{ needs.ReleaseDryRun.outputs.RELEASE_NOTES }}
57+
steps:
58+
- uses: actions/checkout@v4
59+
- name: Update module meta
60+
run: |
61+
RESULT='${{ needs.ReleaseDryRun.outputs.RESULT }}'
62+
VERSION='${{ needs.ReleaseDryRun.outputs.VERSION }}'
63+
RELEASE_NOTES='${{ needs.ReleaseDryRun.outputs.RELEASE_NOTES }}'
64+
65+
echo "🕘 Updating module meta..."
66+
echo " - RESULT: ${RESULT}"
67+
echo " - VERSION: ${VERSION}"
68+
echo " - RELEASE_NOTES: ${RELEASE_NOTES}"
9369
94-
# if [ "${RESULT}" == "SUCCESS" ]; then
95-
# DATE=`date +%Y-%m-%d`
96-
# FILE_CHANGELOG="RELEASE-NOTES.md"
97-
# FILE_MODULE="module.go"
98-
# head -1 ${FILE_CHANGELOG} > .temp.md
99-
# echo -e "\n## ${DATE} - v${VERSION}\n\n${RELEASE_NOTES}" >> .temp.md
100-
# tail -n +2 ${FILE_CHANGELOG} >> .temp.md
101-
# mv -f .temp.md ${FILE_CHANGELOG}
102-
# echo ========== content of ${FILE_CHANGELOG} ==========
103-
# cat ${FILE_CHANGELOG}
104-
#
105-
# sed -i -E "s/^(\s*Version\s*=\s*)\"[^\"]+\"/\1\"${VERSION}\"/" ${FILE_MODULE}
106-
# echo ========== content of ${FILE_MODULE} ==========
107-
# cat ${FILE_MODULE}
108-
#
109-
# echo ========== update .go files ==========
110-
# sed -i -E "s/<<VERSION>>/v${VERSION}/" ./*.go
111-
#
112-
# echo ========== commit updates ==========
113-
# git config --global user.email "<>"
114-
# git config --global user.name "CI Build"
115-
# git commit -am "Update ${FILE_CHANGELOG} and ${FILE_MODULE} for new version ${VERSION}"
116-
# git push origin ${BRANCH_TO_RELEASE}
117-
#
118-
# echo ========== tag ==========
119-
# git tag -f -a "${TAG_PREFIX}${VERSION}" -m "Release ${TAG_PREFIX}/v${VERSION}"
120-
# git push origin "${TAG_PREFIX}${VERSION}" -f
121-
# echo "✅ Done."
122-
# else
123-
# echo "❎ SKIPPED."
124-
# fi
70+
if [ "${RESULT}" == "SUCCESS" ]; then
71+
DATE=`date +%Y-%m-%d`
72+
FILE_CHANGELOG="RELEASE-NOTES.md"
73+
FILE_MODULE="module.go"
74+
head -1 ${FILE_CHANGELOG} > .temp.md
75+
echo -e "\n## ${DATE} - v${VERSION}\n\n${RELEASE_NOTES}" >> .temp.md
76+
tail -n +2 ${FILE_CHANGELOG} >> .temp.md
77+
mv -f .temp.md ${FILE_CHANGELOG}
78+
echo ========== content of ${FILE_CHANGELOG} ==========
79+
cat ${FILE_CHANGELOG}
12580
126-
# MergeToMaster:
127-
# runs-on: ubuntu-latest
128-
# needs: [ 'Release' ]
129-
# permissions:
130-
# pull-requests: write # to be able to create PRs or comment on released PRs
131-
# steps:
132-
# - uses: actions/github-script@v7
133-
# env:
134-
# RESULT: ${{ needs.Release.outputs.RESULT }}
135-
# RELEASE_NOTES: ${{ needs.Release.outputs.RELEASE_NOTES }}
136-
# with:
137-
# script: |
138-
# if (process.env['RESULT'] != 'SUCCESS') {
139-
# console.log('❎ SKIPPED.');
140-
# return;
141-
# }
142-
# const {data: pr} = await github.rest.pulls.create({
143-
# owner: context.repo.owner,
144-
# repo: context.repo.repo,
145-
# title: "Merge branch semver to master after releasing new version ${{ needs.Release.outputs.VERSION }}",
146-
# body: process['env']['RELEASE_NOTES'],
147-
# head: process['env']['BRANCH_TO_RELEASE'],
148-
# base: 'master',
149-
# maintainer_can_modify: true,
150-
# });
151-
# console.log('✅ Created PR: ', pr);
81+
sed -i -E "s/^(\s*Version\s*=\s*)\"[^\"]+\"/\1\"${VERSION}\"/" ${FILE_MODULE}
82+
echo ========== content of ${FILE_MODULE} ==========
83+
cat ${FILE_MODULE}
84+
85+
echo ========== update .go files ==========
86+
sed -i -E "s/<<VERSION>>/v${VERSION}/" ./*.go
87+
88+
echo ========== commit updates ==========
89+
git config --global user.email "<>"
90+
git config --global user.name "CI Build"
91+
git commit -am "Update ${FILE_CHANGELOG}, ${FILE_MODULE} and *.go files for new version ${VERSION}"
92+
git push origin ${BRANCH_TO_RELEASE}
93+
94+
echo ========== tag ==========
95+
git tag -f -a "${TAG_PREFIX}${VERSION}" -m "Release ${TAG_PREFIX}/v${VERSION}"
96+
git push origin "${TAG_PREFIX}${VERSION}" -f
97+
echo "✅ Done."
98+
else
99+
echo "❎ SKIPPED."
100+
fi
101+
102+
MergeToMain:
103+
runs-on: ubuntu-latest
104+
needs: [ Release ]
105+
permissions:
106+
pull-requests: write # to be able to create PRs or comment on released PRs
107+
steps:
108+
- uses: actions/github-script@v7
109+
env:
110+
RESULT: ${{ needs.Release.outputs.RESULT }}
111+
RELEASE_NOTES: ${{ needs.Release.outputs.RELEASE_NOTES }}
112+
with:
113+
script: |
114+
if (process.env['RESULT'] != 'SUCCESS') {
115+
console.log('❎ SKIPPED.');
116+
return;
117+
}
118+
const {data: pr} = await github.rest.pulls.create({
119+
owner: context.repo.owner,
120+
repo: context.repo.repo,
121+
title: "Merge to main after releasing new version ${{ needs.Release.outputs.VERSION }}",
122+
body: process['env']['RELEASE_NOTES'],
123+
head: process['env']['BRANCH_TO_RELEASE'],
124+
base: 'main',
125+
maintainer_can_modify: true,
126+
});
127+
console.log('✅ Created PR: ', pr);

README.md

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ Template to quickly spin up a Go module project.
1515
- `ci.yaml`: automatically run tests and generate code coverage report.
1616
- `release.yaml`: automatically create a new release.
1717

18-
**Workflow**
19-
20-
Workflow implemented by this template is as follows:
21-
22-
- Dependencies are checked and updated weekly by `dependabot.yaml`, and then PRs are automatically merged to `main` branch by `automerge-dependabot.yaml`.
23-
- `ci.yaml` is triggered on every push to any branch to run tests and generate code coverage report.
24-
- Once PR is approved and merged to `release` branch, `release.yaml` is triggered to create a new release. Then a new PR is created to merge `release` branch to `main` branch.
25-
2618
## Usage
2719

2820
1. Create new project from this template:
@@ -35,6 +27,23 @@ Workflow implemented by this template is as follows:
3527
5. Update other files to suit your needs.
3628
6. Happy coding!
3729

30+
**Workflows**
31+
32+
Workflows implemented by this template are as the following:
33+
34+
- Dependencies are checked and updated weekly by `dependabot.yaml`, and then PRs are automatically merged to `main` branch by `automerge-dependabot.yaml`.
35+
- `ci.yaml` is triggered on every push to any branch to run tests and generate code coverage report.
36+
- Once PR is approved and merged to `release` branch, `release.yaml` is triggered to create a new release. Then a new PR is created to merge `release` branch to `main` branch.
37+
38+
A suggested git workflow to use with this template is as the following:
39+
40+
- Work on your code in development/feature branches as usual.
41+
- Once ready, create a PR to merge your development/feature branch to `release` branch.
42+
- Workflow `release.yaml` will be triggered to create a new release.
43+
- Then a new PR will be created to merge `release` branch to `main` branch. Note: you have to review and approve the PR by yourself to finalize the merge.
44+
45+
> Remember to enable the setting "Allow GitHub Actions to create and approve pull requests" from project's `Settings -> Actions -> General`.
46+
3847
## License
3948

4049
This template is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.

RELEASE-NOTES.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
# go-module-template release notes
22

3-
## 2023-08-xx - v0.1.0
3+
## 2023-11-26 - v0.1.0
4+
5+
### Added/Refactoring
6+
7+
- Added matrix strategy test
8+
- Added templates for LICENSE, README and RELEASE-NOTES files
9+
- add sample code and tests
10+
11+
### Fixed/Improvement
12+
13+
- fix release action
14+
15+
## 2023-11-25 - v0.1.0
416

517
Template for Go module projects:
618
- Dependencies version updates with dependabot.
719
- GitHub Actions for auto-merging PRs created by dependabot.
8-
- GitHub Actions for CI/CD.
20+
- GitHub Actions for CI/CD and auto-releasing.

0 commit comments

Comments
 (0)