-
Notifications
You must be signed in to change notification settings - Fork 1
170 lines (144 loc) · 4.84 KB
/
publish.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
on:
workflow_dispatch:
inputs:
release:
type: string
required: false
description: 'e.g: v0.1.0'
build:
type: boolean
required: true
default: true
publish:
type: boolean
required: true
default: true
release:
types:
- published
permissions:
contents: write
name: Publish
env:
RELEASE: ${{ inputs.release || github.event.release.tag_name }}
jobs:
prepare-cargo:
if: ${{ github.event.release || inputs.build }}
runs-on: ubuntu-latest
steps:
- name: cache cargo binaries
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
key: ${{ runner.os }}-cargo
- name: install cross binary
run: |
cargo install cross --git https://github.com/cross-rs/cross || true
publish-binaries:
if: ${{ github.event.release || inputs.build }}
needs:
- prepare-cargo
runs-on: ubuntu-latest
strategy:
matrix:
include:
- name: pse-linux-amd64
target: x86_64-unknown-linux-musl
- name: pse-linux-arm64
target: aarch64-unknown-linux-musl
- name: pse-linux-arm6
target: arm-unknown-linux-musleabihf
- name: pse-linux-arm7
target: armv7-unknown-linux-musleabihf
steps:
- name: use cached cargo binaries
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
key: ${{ runner.os }}-cargo
- uses: actions/checkout@v4
- name: use cached dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-target-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: build
run: cross build --release --target ${{ matrix.target }}
- name: prepare binary
run: cp ./target/${{ matrix.target }}/release/pse ./${{ matrix.name }}
- name: verify binary
run: ls -l
- name: publish binary
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: gh release upload ${{ env.RELEASE }} ./${{ matrix.name }} --clobber
publish-docker:
if: ${{ always() && (github.event.release || inputs.publish) }}
needs:
- publish-binaries
runs-on: ubuntu-latest
env:
REPO: ${{ github.repository }}
steps:
- uses: actions/checkout@v4
- name: build args
id: build-args
run: |
VERSION=${RELEASE}
if [[ $VERSION =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
TAGS="${REPO}:latest"
TAGS="${TAGS},${REPO}:${MAJOR}"
TAGS="${TAGS},${REPO}:${MAJOR}.${MINOR}"
TAGS="${TAGS},${REPO}:${MAJOR}.${MINOR}.${PATCH}"
else
echo "Bad version detected: ${VERSION}"
exit 1
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
- name: set up QEMU
uses: docker/[email protected]
- name: set up docker buildx
uses: docker/[email protected]
- name: login to docker hub
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: download published binaries
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release download ${{ env.RELEASE }} -D ./release
- name: build and push docker image
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile.release
platforms: |
linux/amd64
linux/arm64
linux/arm/v6
linux/arm/v7
target: release
push: true
tags: ${{ steps.build-args.outputs.tags }}
labels: |
version=${{ steps.build-args.outputs.version }}
org.opencontainers.image.version=${{ steps.build-args.outputs.version }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}