-
Notifications
You must be signed in to change notification settings - Fork 0
148 lines (145 loc) · 5.38 KB
/
create-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Create Release
on:
workflow_dispatch:
inputs:
draft:
type: choice
description: "Create the release as draft"
options:
- "yes"
- "no"
default: "no"
required: true
force:
type: choice
description: "Force the creation of a release (even if no PR are found)"
options:
- "yes"
- "no"
default: "no"
required: true
jobs:
release:
runs-on: ubuntu-22.04
permissions:
contents: write
packages: write
pull-requests: write
outputs:
tag: ${{ steps.output.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # we need this because fetch-tags=true and because of a GHA bug: https://github.com/actions/checkout/issues/1471
fetch-tags: true
- uses: actions/setup-go@v4
with:
go-version: "1.21"
- id: create-release
uses: fabien-marty/github-create-next-semantic-release-action@main
with:
github-token: ${{ github.token }} # Let's use the default value of the current workflow
repository: ${{ github.repository }} # Let's use the default value of the current workflow
repository-owner: ${{ github.repository_owner }} # Let's use the default value of the current workflow
release-force: ${{ github.event.inputs.force == 'yes' }}
release-draft: ${{ github.event.inputs.draft == 'yes' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set output
id: output
run: |
echo "tag=${{ steps.create-release.outputs.new-tag}}" >>"$GITHUB_OUTPUT"
- name: "Build"
run: |
make build
- name: "Generate Changelog"
run: |
./cmd/github-generate-changelog/github-generate-changelog --branch main . >CHANGELOG.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create a Changelog PR
run: |
DIFF=$(git status --short)
if test "${DIFF}" = ""; then
echo "No changes to commit => exit here"
exit 0
fi
BRANCH="automatic-changelog"
N=`git fetch origin "${BRANCH}" 2>/dev/null || echo "NOTFOUND"`
if test "${N}" = "NOTFOUND"; then
echo "Branch: ${BRANCH} does not exist, let's create a new branch..."
git checkout -b "${BRANCH}"
else
echo "Branch: ${BRANCH} already exists, let's reset this branch with ${GITHUB_REF}..."
git stash save --include-untracked
git checkout -b "${BRANCH}" "origin/${BRANCH}"
git reset --hard "${GITHUB_REF}"
git stash apply
fi
echo "Let's commit and push the changes..."
git config --global user.name 'Automatic Changelog'
git config --global user.email '[email protected]'
git add -A
git commit -m "Automatic Changelog"
git push -u origin -f "${BRANCH}"
echo "Checking existing PRs for head:${BRANCH}..."
N=`gh pr list --search "head:${BRANCH} is:pr is:open" --json number |grep number || true`
if test "${N}" != ""; then
echo "There is already an open PR for this branch => exit here"
exit 0
fi
echo "Let's create the PR"
gh pr create --title "Automatic Changelog" --body "Automatic Changelog" --repo "${{ github.repository }}" --head "${BRANCH}" --label "Type: Hidden"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
release_go_binary:
needs: release
name: Release Go Binary
runs-on: ubuntu-22.04
if: ${{ github.event.inputs.draft == 'no' && needs.release.outputs.tag != '' }}
permissions:
contents: write
packages: write
pull-requests: read
strategy:
matrix:
goos: [linux, windows, darwin]
goarch: [amd64, arm64]
exclude:
- goarch: arm64
goos: windows
steps:
- uses: actions/checkout@v4
- name: Debug
run: |
echo "tag=${{ needs.release.outputs.tag }}"
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
project_path: ./cmd/github-create-next-semantic-release
binary_name: github-create-next-semantic-release
compress_assets: "OFF"
pre_command: export CGO_ENABLED=0
release_tag: ${{ needs.release.outputs.tag }}
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
project_path: ./cmd/github-next-semantic-version
binary_name: github-next-semantic-version
compress_assets: "OFF"
pre_command: export CGO_ENABLED=0
release_tag: ${{ needs.release.outputs.tag }}
- uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
project_path: ./cmd/github-generate-changelog
binary_name: github-generate-changelog
compress_assets: "OFF"
pre_command: export CGO_ENABLED=0
release_tag: ${{ needs.release.outputs.tag }}