Skip to content

Commit fee7c57

Browse files
authored
Add docker build support, improve release (#19)
* Use tag annotation to generate release message. Add sha256 sum of the binaries. Only run tests on branches. * Add docker image build & push
1 parent a4a3508 commit fee7c57

3 files changed

Lines changed: 80 additions & 11 deletions

File tree

.github/workflows/docker-image.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: docker image
2+
on:
3+
push:
4+
branches:
5+
- '*'
6+
- '!master'
7+
release:
8+
types: [published]
9+
10+
jobs:
11+
build_push:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
- name: Prepare
17+
id: prep
18+
run: |
19+
DOCKER_IMAGE=messagebird/gcppromd
20+
VERSION=edge
21+
if [[ '${{ github.event_name }}' == 'release' ]]; then
22+
VERSION=${GITHUB_REF#refs/tags/}
23+
fi
24+
TAGS="${DOCKER_IMAGE}:${VERSION}"
25+
if [ "${{ github.event_name }}" = "push" ]; then
26+
TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}"
27+
fi
28+
echo ::set-output name=version::${VERSION}
29+
echo ::set-output name=tags::${TAGS}
30+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
31+
- name: Set up Docker Buildx
32+
uses: docker/setup-buildx-action@v1
33+
- name: Login to DockerHub
34+
if: ${{ github.event_name == 'release' }}
35+
uses: docker/login-action@v1
36+
with:
37+
username: ${{ secrets.DOCKER_USERNAME }}
38+
password: ${{ secrets.DOCKER_PASSWORD }}
39+
- name: Build and push
40+
uses: docker/build-push-action@v2
41+
with:
42+
context: .
43+
push: ${{ github.event_name == 'release' }}
44+
tags: ${{ steps.prep.outputs.tags }}
45+
labels: |
46+
org.opencontainers.image.source=${{ github.event.repository.html_url }}
47+
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
48+
org.opencontainers.image.revision=${{ github.sha }}

.github/workflows/release.yml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: release
22

33
on:
44
push:
5-
tags: ['v*']
5+
tags: ["v*.*.*"]
66

77
jobs:
88
get-tag:
@@ -14,27 +14,39 @@ jobs:
1414
- id: vars
1515
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
1616
build:
17+
env:
18+
BIN_NAME: ${{ needs.get-tag.outputs.tag }}.${{ matrix.platform.goos }}-${{ matrix.platform.goarch }}
1719
needs: [get-tag]
1820
runs-on: ubuntu-latest
1921
strategy:
2022
matrix:
2123
platform:
22-
- {goos: darwin, goarch: amd64}
23-
- {goos: linux, goarch: amd64}
24-
- {goos: windows, goarch: amd64}
24+
- { goos: darwin, goarch: amd64 }
25+
- { goos: linux, goarch: amd64 }
26+
- { goos: windows, goarch: amd64 }
2527
steps:
2628
- name: Checkout
2729
uses: actions/checkout@v2
2830
- name: Setup go
2931
uses: actions/setup-go@v1
3032
with:
3133
go-version: ^1.0
32-
- run: CGO_ENABLED=0 GOOS=${{ matrix.platform.goos }} GOARCH=${{ matrix.platform.goarch }} go build -ldflags "-s -w" -o gcppromd-${{ needs.get-tag.outputs.tag }}.${{ matrix.platform.goos }}-${{ matrix.platform.goarch }} ./cmd/gcppromd
34+
- name: Set binary name
35+
id: binary_name
36+
run: |
37+
echo "BIN_NAME=gcppromd-${{ needs.get-tag.outputs.tag }}.${{ matrix.platform.goos }}-${{ matrix.platform.goarch }}" >> $GITHUB_ENV
38+
- run: >-
39+
CGO_ENABLED=0 GOOS=${{ matrix.platform.goos }}
40+
GOARCH=${{ matrix.platform.goarch }}
41+
go build -ldflags "-s -w" -o ${{ env.BIN_NAME }} ./cmd/gcppromd &&
42+
shasum -a 256 ${{ env.BIN_NAME }} > ${{ env.BIN_NAME }}.sha256
3343
- name: Upload binary
3444
uses: actions/upload-artifact@v2
3545
with:
36-
name: binary.${{ matrix.platform.goos }}-${{ matrix.platform.goarch }}
37-
path: gcppromd-${{ needs.get-tag.outputs.tag }}.${{ matrix.platform.goos }}-${{ matrix.platform.goarch }}
46+
name: binary.${{ env.BIN_NAME }}
47+
path: |
48+
${{ env.BIN_NAME }}
49+
${{ env.BIN_NAME }}.sha256
3850
if-no-files-found: error
3951
release:
4052
needs: [get-tag, build]
@@ -45,12 +57,18 @@ jobs:
4557
- uses: actions/download-artifact@v2
4658
with:
4759
path: .
60+
# git fetch --tags --force is required because GitHub checkout action doesn't seems to preserve the tag annotation.
61+
- name: Retrive release message
62+
run: |
63+
echo 'RELEASE_MSG<<EOF' >> $GITHUB_ENV
64+
git fetch --tags --force && git tag -l --format='%(contents)' ${{ needs.get-tag.outputs.tag }} >> $GITHUB_ENV
65+
echo 'EOF' >> $GITHUB_ENV
4866
- name: Release
4967
uses: softprops/action-gh-release@v1
5068
with:
5169
draft: true
52-
body_path: CHANGELOGS/${{ needs.get-tag.outputs.tag }}.md
70+
body: ${{ env.RELEASE_MSG }}
5371
files: |
5472
binary.*/*
5573
env:
56-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: test
2-
on: push
3-
2+
on:
3+
push:
4+
branches:
5+
- '*'
6+
- '!master'
47
jobs:
58
test:
69
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)