-
Notifications
You must be signed in to change notification settings - Fork 1
185 lines (168 loc) · 6.23 KB
/
git-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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
name: "Git Release"
permissions:
contents: "write"
on:
workflow_run:
workflows: ["Git Tag"]
types:
- "completed"
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# name of image
IMAGE: docker-autoheal
# github.repository as <account>/<repo>
IMAGE_NAME: tmknight/docker-autoheal
# cosign version
COSIGN_VER: 'v2.1.1'
# Build args
CONTEXT: .
DISTRO: alpine
RELEASE: stable
jobs:
get-tag:
name: "Get Tag From Package Version"
runs-on: "ubuntu-latest"
outputs:
pkg-version: ${{ steps.pkg-version.outputs.PKG_VERSION }}
steps:
- name: "Check out the repo"
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: "Get tag"
id: "pkg-version"
shell: "bash"
run: |
echo PKG_VERSION=$(awk -F ' = ' '$1 ~ /^version/ { gsub(/["]/, "", $2); printf("%s",$2) }' Cargo.toml) >> $GITHUB_OUTPUT
create-release:
name: "Create release"
if: ${{ github.event.workflow_run.conclusion == 'success' }}
needs: "get-tag"
runs-on: "ubuntu-latest"
steps:
- name: "Check out the repo"
uses: actions/checkout@v3
- name: "Create release"
uses: "taiki-e/create-gh-release-action@v1"
with:
# (optional) Path to changelog.
# changelog: CHANGELOG.md
branch: "main"
ref: refs/tags/v${{ needs.get-tag.outputs.pkg-version }}
token: ${{ secrets.GITHUB_TOKEN }}
upload-assets:
name: "Upload assets to Github releases"
if: ${{ github.event.workflow_run.conclusion == 'success' }}
needs:
- "get-tag"
- "create-release"
strategy:
matrix:
include:
- target: "x86_64-unknown-linux-gnu"
os: "ubuntu-latest"
- target: "x86_64-unknown-linux-musl"
os: "ubuntu-latest"
- target: "aarch64-unknown-linux-gnu"
os: "ubuntu-latest"
- target: "aarch64-unknown-linux-musl"
os: "ubuntu-latest"
# - target: "aarch64-unknown-openbsd"
# os: "ubuntu-latest"
runs-on: ${{ matrix.os }}
steps:
- name: "Check out the repo"
uses: actions/checkout@v3
- name: "Upload Binaries"
uses: "taiki-e/upload-rust-binary-action@v1"
with:
bin: ${{ env.IMAGE }}
target: ${{ matrix.target }}
archive: $bin-${{ matrix.target }}
ref: refs/tags/v${{ needs.get-tag.outputs.pkg-version }}
token: ${{ secrets.GITHUB_TOKEN }}
push-to-registry:
name: "Publish Docker image"
if: ${{ github.event.workflow_run.conclusion == 'success' }}
needs:
- "get-tag"
- "upload-assets"
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@v3 #v3.1.1
with:
cosign-release: ${{ env.COSIGN_VER }}
# Setup QEMU for multi-arch
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: amd64,arm64
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch,enable=${{ github.event_name != 'schedule' }}
type=ref,event=tag
# type=raw,enable=${{ github.event_name == 'schedule' }},value=latest
type=raw,enable=true,value=latest
type=raw,enable=true,value=v${{ needs.get-tag.outputs.pkg-version }}
# type=raw,enable=true,value=${{ env.DISTRO }}-${{ env.RELEASE }}
# type=raw,enable=true,value=${{ env.DISTRO }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v4
with:
context: ${{ env.CONTEXT }}
platforms: linux/amd64,linux/arm64
file: docker/${{ env.DISTRO }}/${{ env.RELEASE }}/${{ env.IMAGE }}.dockerfile
build-args: ${{ env.BUILD_ARGS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}