-
Notifications
You must be signed in to change notification settings - Fork 2
142 lines (129 loc) · 4.86 KB
/
publish-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
name: Publish GitHub releases
on:
workflow_dispatch:
push:
tags:
- '[v]?[0-9]+.[0-9]+.[0-9]+'
jobs:
publish-binaries:
name: Publishing for ${{ matrix.job.os }}
runs-on: ${{ matrix.job.os }}
strategy:
matrix:
job:
- os: macos-latest
os-name: macos
target: x86_64-apple-darwin
architecture: x86_64
binary-postfix: ""
use-cross: false
- os: ubuntu-latest
os-name: linux
target: x86_64-unknown-linux-musl
architecture: x86_64
binary-postfix: ""
use-cross: false
- os: windows-latest
os-name: windows
target: x86_64-pc-windows-msvc
architecture: x86_64
binary-postfix: ".exe"
use-cross: false
# TODO: re-enable this but need to figure out how to cross-compile for ARM64 using MUSL
# Seems like the details are https://jensd.be/1126/linux/cross-compiling-for-arm-or-aarch64-on-debian-or-ubuntu
#- os: ubuntu-latest
# os-name: linux
# target: aarch64-unknown-linux-musl
# architecture: arm64
# binary-postfix: ""
# use-cross: true
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
target: ${{ matrix.job.target }}
- uses: Swatinem/rust-cache@v1
- name: Install Ubuntu MUSL deps
run: |
sudo apt-get install musl musl-dev musl-tools
if: matrix.job.os-name == 'linux'
- name: Cargo build
uses: actions-rs/cargo@v1
with:
command: build
use-cross: ${{ matrix.job.use-cross }}
args: --release --target ${{ matrix.job.target }} --package ssstar-cli
env:
RUSTFLAGS: '-C target-feature=+crt-static'
- name: install strip command
shell: bash
run: |
if [[ ${{ matrix.job.target }} == aarch64-unknown-linux-gnu ]]; then
sudo apt update
sudo apt-get install -y binutils-aarch64-linux-gnu
fi
- name: Packaging final binary
shell: bash
run: |
cd target/${{ matrix.job.target }}/release
####### reduce binary size by removing debug symbols #######
BINARY_NAME=ssstar${{ matrix.job.binary-postfix }}
if [[ ${{ matrix.job.target }} == aarch64-unknown-linux-gnu ]]; then
GCC_PREFIX="aarch64-linux-gnu-"
else
GCC_PREFIX=""
fi
"$GCC_PREFIX"strip $BINARY_NAME
########## create tar.gz ##########
if [[ "${{ startsWith(github.ref, 'refs/tags/v') }}" == "true" ]]; then
VERSION=${GITHUB_REF/refs\/tags\//}
else
VERSION=master
fi
RELEASE_NAME=ssstar-${VERSION}-${{ matrix.job.os-name }}-${{ matrix.job.architecture }}
tar czvf $RELEASE_NAME.tar.gz $BINARY_NAME
########## create sha256 ##########
if [[ ${{ runner.os }} == 'Windows' ]]; then
certutil -hashfile $RELEASE_NAME.tar.gz sha256 | grep -E [A-Fa-f0-9]{64} > $RELEASE_NAME.sha256
else
shasum -a 256 $RELEASE_NAME.tar.gz > $RELEASE_NAME.sha256
fi
- name: Releasing assets
uses: softprops/action-gh-release@v1
with:
files: |
target/${{ matrix.job.target }}/release/ssstar-*.tar.gz
target/${{ matrix.job.target }}/release/ssstar-*.sha256
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: startsWith(github.ref, 'refs/tags/v')
publish-docker:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Build docker image
shell: bash
run: |
# Tag the docker image with the full semver, major.minor, and major
version=$(cargo metadata --format-version 1 --manifest-path ssstar-cli/Cargo.toml \
| jq -r ".packages[]|select(.name == \"ssstar-cli\")|.version")
major_minor=$(echo $version | sed -r 's/([0-9]+\.[0-9]+).*$/\1/')
major=$(echo $version | sed -r 's/([0-9]+)\.[0-9]+.*$/\1/')
docker build . \
--tag ssstar:latest \
--tag ghcr.io/elastio/ssstar:latest \
--tag ghcr.io/elastio/ssstar:$version \
--tag ghcr.io/elastio/ssstar:$major_minor \
--tag ghcr.io/elastio/ssstar:$major
docker images
- name: Publish to GitHub Container Registry
run: |
echo $GITHUB_TOKEN | docker login ghcr.io -u USERNAME --password-stdin
docker push --all-tags ghcr.io/elastio/ssstar
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: startsWith(github.ref, 'refs/tags/v')