-
Notifications
You must be signed in to change notification settings - Fork 0
116 lines (101 loc) · 3.32 KB
/
ci.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
name: CI
on:
push:
paths:
- 'source/**.go'
- 'go.mod'
- '.github/workflows/*.yml'
branches:
- '**'
tags:
- '*.*.*'
workflow_dispatch:
env:
PROJECT_NAME: kasa-smart-plug
jobs:
build:
name: Build
runs-on: ubuntu-22.04
strategy:
matrix:
operatingSystem: [ 'linux', 'windows' ]
architecture: [ 'amd64', '386', 'arm64', 'arm' ]
library: [ '', 'glibc', 'musl' ]
exclude:
- operatingSystem: windows
library: glibc
- operatingSystem: windows
library: musl
- operatingSystem: linux
library: ''
permissions:
contents: read
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
- name: Install build tools
if: ${{ matrix.library == 'musl' }}
run: sudo apt-get install --no-install-recommends --yes musl-tools
- name: Create artifact & executable name
id: names
env:
PROJECT_NAME: ${{ env.PROJECT_NAME }}
OPERATING_SYSTEM: ${{ matrix.operatingSystem }}
ARCHITECTURE: ${{ matrix.architecture }}
LIBRARY: ${{ matrix.library }}
uses: actions/github-script@v7
with:
script: |
const { PROJECT_NAME, OPERATING_SYSTEM, ARCHITECTURE, LIBRARY } = process.env;
const artifactName = [ PROJECT_NAME, OPERATING_SYSTEM, ARCHITECTURE, LIBRARY ]
.filter( value => value != '' )
.join( '-' );
const executableName = artifactName + ( OPERATING_SYSTEM == 'windows' ? '.exe' : '' );
core.setOutput( 'artifact', artifactName );
core.setOutput( 'executable', executableName );
- name: Build executable
env:
GOOS: ${{ matrix.operatingSystem }}
GOARCH: ${{ matrix.architecture }}
CC: ${{ matrix.library == 'musl' && '/usr/bin/musl-gcc' || '' }}
run: go build -v -ldflags='-s -w' -o ${{ steps.names.outputs.executable }} ./source/
- name: Upload build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ steps.names.outputs.artifact }}
path: ${{ steps.names.outputs.executable }}
release:
name: Release
runs-on: ubuntu-22.04
needs: build
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
permissions:
contents: write
steps:
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Move executables
run: |
mv -v artifacts/${{ env.PROJECT_NAME }}-*/${{ env.PROJECT_NAME }}-* ./
rm -v -r artifacts
- name: Calculate checksums
run: |
md5sum ${{ env.PROJECT_NAME }}-* > MD5SUMS.txt
sha1sum ${{ env.PROJECT_NAME }}-* > SHA1SUMS.txt
sha256sum ${{ env.PROJECT_NAME }}-* > SHA256SUMS.txt
sha512sum ${{ env.PROJECT_NAME }}-* > SHA512SUMS.txt
- name: Create draft release
uses: softprops/action-gh-release@v1
with:
draft: true
tag_name: ${{ github.ref_name }}
files: |
${{ env.PROJECT_NAME }}-*
*SUMS.txt
token: ${{ secrets.GITHUB_TOKEN }}