forked from fabianlee/golang-github-action-example
-
Notifications
You must be signed in to change notification settings - Fork 0
85 lines (70 loc) · 2.22 KB
/
github-actions-release.yml
File metadata and controls
85 lines (70 loc) · 2.22 KB
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
name: build-release-binary
run-name: Create Github Release for GoLang binary
on:
push:
#branches:
#- main
tags:
- 'r*'
jobs:
build:
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
# debug
- name: Dump env
run: env | sort
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- uses: actions/checkout@v3
with:
fetch-depth: 0 # get all tags, needed to get git log
ref: main
# Go environment
- name: setup Go Lang
uses: actions/setup-go@v3
with:
go-version: '^1.19.2'
- run: |
go version
cd src
go mod init ${GITHUB_REPOSITORY}
go mod tidy
go build -ldflags "-X main.Version=${GITHUB_REF_NAME} -X main.BuiltBy=github-actions" main.go
- run: git version
- run: git branch
- run: git tag
- name: get semantic tag version and release notes from commit messages
id: tag
run: |
curtag=${GITHUB_REF_NAME}
major_minor=$(echo "$curtag" | cut -d'.' -f1-2)
patch=$(echo "$curtag" | cut -d'.' -f3)
# avoid empty patch number
[ -n "$patch" ] && ((patch--)) || patch=".x"
prevtag="${major_minor}.${patch}"
echo "" > body.log
if git tag | grep $prevtag ; then
git log -q ${curtag}...${prevtag} --pretty="- %s" -q --no-color >> body.log
else
git log --pretty="- %s" -q --no-color >> body.log
fi
line_count=$(cat body.log | wc -l)
echo "curtag=$curtag" >> $GITHUB_OUTPUT
echo "prevtag=$prevtag" >> $GITHUB_OUTPUT
echo "line_count=$line_count" >> $GITHUB_OUTPUT
- run: echo curtag is ${{ steps.tag.outputs.curtag }}
- run: echo prevtag is ${{ steps.tag.outputs.prevtag }}
- run: echo line_count is ${{ steps.tag.outputs.line_count }}
- run: cat body.log
# create Github release with release note from file and binary asset attached
- uses: ncipollo/release-action@v1
with:
name: ${{ env.GITHUB_REF_NAME }}
tag: ${{ env.GITHUB_REF_NAME }}
artifacts: "src/main"
bodyFile: "body.log"
token: ${{ secrets.GITHUB_TOKEN }}