-
Notifications
You must be signed in to change notification settings - Fork 55
122 lines (108 loc) · 3.65 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
116
117
118
119
120
121
122
name: Release
on:
push:
tags:
- '*'
env:
GOLANG_VERSION: 1.17
jobs:
create_release:
name: Create release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Get version from GITHUB_REF
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
- 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 }}
body: |
See changelog [here](https://github.com/chop-dbhi/prometheus-sql/blob/${{ steps.get_version.outputs.VERSION }}/CHANGELOG.md)
draft: false
prerelease: false
release_pkg:
name: Build release packages
needs: create_release
runs-on: ubuntu-latest
strategy:
matrix:
os: [darwin, linux, windows]
include:
- os: darwin
arch: amd64
pkg_cmd: tar -czvf
pkg_file: prometheus-sql-darwin-amd64.tar.gz
content_type: application/tar+gzip
- os: linux
arch: amd64
pkg_cmd: tar -czvf
pkg_file: prometheus-sql-linux-amd64.tar.gz
content_type: application/tar+gzip
- os: windows
arch: amd64
pkg_cmd: zip
pkg_file: prometheus-sql-windows-amd64.zip
content_type: application/zip
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v3
with:
go-version: ^${{ env.GOLANG_VERSION }}
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Verify go modules
run: go mod verify
- name: Check formatting
run: |
chmod +x $GITHUB_WORKSPACE/scripts/gofmtcheck.sh
$GITHUB_WORKSPACE/scripts/gofmtcheck.sh
- name: Linting
if: matrix.os == 'linux'
run: |
go install golang.org/x/lint/golint@latest
golint .
- name: Get short commit hash and date
id: get_git_info
run: echo ::set-output name=HASH_DATE::$(git log -1 --pretty=format:"%h (%ci)" .)
- name: Build
run: |
mkdir -p dist/${GOOS}-${GOARCH}
go build -v -ldflags "-X \"main.buildVersion=${{ steps.get_git_info.outputs.HASH_DATE }}\"" -o dist/${GOOS}-${GOARCH}/ .
- name: Package
run: |
cd dist && ${{ matrix.pkg_cmd }} ${{ matrix.pkg_file }} ${GOOS}-${GOARCH}/*
pwd && ls -l
- name: Upload asset to release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./dist/${{ matrix.pkg_file }}
asset_name: ${{ matrix.pkg_file }}
asset_content_type: ${{ matrix.content_type }}
# - name: Build Docker image and push
# if: matrix.os == 'linux' && env.DOCKER_USERNAME != ''
# uses: docker/build-push-action@v1
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
# repository: dbhi/prometheus-sql
# tag_with_sha: true
# tag_with_ref: true
# add_git_labels: true
# dockerfile: Dockerfile.github
# push: ${{ startsWith(github.ref, 'refs/tags/') }}
# env:
# DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}