-
Notifications
You must be signed in to change notification settings - Fork 0
115 lines (100 loc) · 3.93 KB
/
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
name: Release
on:
push:
tags:
- 'v*'
jobs:
create_release:
name: Create release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: true
releases-build_release:
name: Build release by matrix
needs: create_release
runs-on: ubuntu-latest
strategy:
matrix:
goos: [ linux, windows ]
goarch: [ amd64, arm64 ]
exclude:
# windows/arm64 seems useless
- goarch: arm64
goos: windows
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Set up GoLang
uses: actions/setup-go@v2.1.3
with:
go-version: ^1.15
id: go
- name: Get dependencies
run: |
go version
go get -v -t -d ./...
- name: Setup environment
run: |
echo APP_VERSION=$(basename ${GITHUB_REF}) >> $GITHUB_ENV
echo BUILD_TIME=$(date -u +"%Y%m%d-%H:%M:%S") >> $GITHUB_ENV
echo BUILD_USER=$(echo ${GITHUB_ACTOR}@${HOSTNAME}) >> $GITHUB_ENV
echo BUILD_ARTIFACTS_FOLDER=$(echo build-artifacts-$(date +%s)) >> $GITHUB_ENV
echo BINARY_NAME=$(basename ${GITHUB_REPOSITORY}) >> $GITHUB_ENV
echo GOOS=$(echo ${{ matrix.goos }}) >> $GITHUB_ENV
echo GOARCH=$(echo ${{ matrix.goarch }}) >> $GITHUB_ENV
if [ ${{ matrix.goos }} == 'windows' ]; then
echo BINARY_EXT='.exe' >> $GITHUB_ENV
echo RELEASE_ASSET_EXT='.zip' >> $GITHUB_ENV
echo MEDIA_TYPE='application/zip' >> $GITHUB_ENV
else
echo BINARY_EXT='' >> $GITHUB_ENV
echo RELEASE_ASSET_EXT='.tar.gz' >> $GITHUB_ENV
echo MEDIA_TYPE='application/gzip' >> $GITHUB_ENV
fi
- name: Set asset name
run: echo RELEASE_ASSET_NAME=$(echo ${{ env.BINARY_NAME }}-${{ env.APP_VERSION }}-${{ env.GOOS }}-${{ env.GOARCH }}) >> $GITHUB_ENV
- name: Environment Printer
uses: managedkaos/print-env@v1.0
- name: Create directory
run: |
mkdir -p ${BUILD_ARTIFACTS_FOLDER}
cp -r LICENSE README.md cfg.yml ${{ env.BUILD_ARTIFACTS_FOLDER }}/
- name: Build
run: go build -v -o "${{ env.BUILD_ARTIFACTS_FOLDER }}/${{ env.BINARY_NAME }}${{ env.BINARY_EXT }}" -ldflags="-X 'main.Version=${{ env.APP_VERSION }}' -X 'main.BuildDate=${{ env.BUILD_TIME }}' -X 'main.Branch=${{ github.ref }}' -X 'main.Revision=${{ github.SHA }}' -X 'main.BuildUser=${{ env.BUILD_USER }}'" .
- name: List files in directory
run: ls -lha ${{ env.BUILD_ARTIFACTS_FOLDER }}/
- name: TAR/ZIP files
run: |
cd ${{ env.BUILD_ARTIFACTS_FOLDER }}
if [ ${{ env.GOOS }} == 'windows' ]; then
zip -vr ${{ env.RELEASE_ASSET_NAME }}${{ env.RELEASE_ASSET_EXT }} *
echo 'Windows'
else
tar cvfz ${{ env.RELEASE_ASSET_NAME }}${{ env.RELEASE_ASSET_EXT }} *
echo 'Linux'
fi
id: create_tar
- name: List files in directory
run: |
ls -lha ${{ env.BUILD_ARTIFACTS_FOLDER }}/
- name: Publish release asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./${{ env.BUILD_ARTIFACTS_FOLDER }}/${{ env.RELEASE_ASSET_NAME }}${{ env.RELEASE_ASSET_EXT }}
asset_name: ${{ env.RELEASE_ASSET_NAME }}${{ env.RELEASE_ASSET_EXT }}
asset_content_type: ${{ env.MEDIA_TYPE }}