-
-
Notifications
You must be signed in to change notification settings - Fork 47
139 lines (129 loc) · 4.29 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Release new version
on:
push:
tags:
- v*.*.*
jobs:
publish-docker:
name: Build latest Docker image
runs-on: self-hosted
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/DefGuard/defguard
tags: |
type=raw,value=latest
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=sha
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build container
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64
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
create-release:
name: Create GitHub release draft
runs-on: self-hosted
outputs:
upload_url: ${{ steps.release.outputs.upload_url }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create GitHub release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
generate_release_notes: true
build-release:
name: Build release ${{ matrix.build }} binary
needs: [ 'create-release' ]
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
build: [ linux, linux-arm, linux-arm64, freebsd ]
include:
- build: linux
os: self-hosted
asset_name: defguard-linux-x86_64
target: x86_64-unknown-linux-gnu
- build: linux-arm
os: self-hosted
asset_name: defguard-linux-armv7
target: armv7-unknown-linux-gnueabihf
- build: linux-arm64
os: self-hosted
asset_name: defguard-linux-arm64
target: aarch64-unknown-linux-gnu
- build: freebsd
os: self-hosted
asset_name: defguard-freebsd-x86_64
target: x86_64-unknown-freebsd
steps:
# Store the version, stripping any v-prefix
- name: Write release version
run: |
VERSION=${GITHUB_REF_NAME#v}
echo Version: $VERSION
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
- name: Install Rust stable
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: ${{ matrix.target }}
override: true
- name: Build release binary
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --release --target ${{ matrix.target }}
- name: Rename binary
run: mv target/${{ matrix.target }}/release/defguard ${{ matrix.asset_name }}-${{ github.ref_name }}
- name: Strip release binary (linux)
if: matrix.build == 'linux'
run: strip "${{ matrix.asset_name }}-${{ github.ref_name }}"
- name: Tar
uses: a7ul/[email protected]
with:
command: c
files: |
${{ matrix.asset_name }}-${{ github.ref_name }}
outPath: ${{ matrix.asset_name }}-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
- name: Upload release archive
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create-release.outputs.upload_url }}
asset_path: ${{ matrix.asset_name }}-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
asset_name: ${{ matrix.asset_name }}-${{ github.ref_name }}-${{ matrix.target }}.tar.gz
asset_content_type: application/octet-stream