forked from SumoLogic-Labs/sumocli
-
Notifications
You must be signed in to change notification settings - Fork 0
90 lines (83 loc) · 2.84 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
name: goreleaser
on:
push:
# run only against tags
tags:
- '*'
permissions:
contents: write
packages: write
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0
- uses: actions/setup-go@v4
with:
go-version: stable
# More assembly might be required: Docker logins, GPG, etc. It all depends
# on your needs.
- uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
name: build
runs-on: ubuntu-latest
container: ghcr.io/dpc-sdp/bay/ci-builder:6.x
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build the controller image
run: docker build -f Dockerfile -t sumocli .
- name: Log in to github container registry
run: |
GITHUB_USER=$(curl -sSL -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/user | gojq -r .login)
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u "${GITHUB_USER}" --password-stdin
- name: Get tag
if: startsWith(github.ref, 'refs/tags/')
run: echo "TAG_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Create tagged release
if: startsWith(github.ref, 'refs/tags/')
run: |
docker tag sumocli ghcr.io/dpc-sdp/sumocli:$TAG_VERSION
- name: Push tagged release
if: startsWith(github.ref, 'refs/tags/')
run: |
docker push ghcr.io/dpc-sdp/sumocli:$TAG_VERSION
# Check if this tag is the latest release, if so tag with latest.
- name: Check if latest release
id: check_latest_release
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const tag = context.ref.replace('refs/tags/', '');
const owner = context.repo.owner;
const repo = context.repo.repo;
try {
const latestRelease = await github.repos.getLatestRelease({
owner,
repo,
});
const isLatest = (latestRelease.data.tag_name === tag);
return { isLatestRelease: isLatest };
} catch (error) {
if (error.status === 404) {
// No latest release found
return { isLatestRelease: false };
} else {
throw error;
}
}
- name: Tag image with latest
if: steps.check_latest_release.outputs.isLatestRelease == 'true'
run: |
docker tag sumocli ghcr.io/dpc-sdp/sumocli:latest
docker push ghcr.io/dpc-sdp/sumocli:latest