forked from ukchukx/rocksdb-rust
-
Notifications
You must be signed in to change notification settings - Fork 1
137 lines (132 loc) · 5.3 KB
/
ci.yaml
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
name: build and release
on:
workflow_dispatch:
release:
types: [created]
permissions:
contents: write
env:
DOCKERHUB_REPO: ${{ vars.DOCKERHUB_USER }}/smol-kv
jobs:
build:
name: ${{ matrix.platform.os_name }} with rust ${{ matrix.toolchain }}
runs-on: ${{ matrix.platform.os }}
strategy:
fail-fast: false
matrix:
platform:
- os_name: Linux-aarch64
os: ubuntu-20.04
target: aarch64-unknown-linux-musl
bin: ${{ github.event.repository.name }}-linux-arm64
- os_name: Linux-x86_64
os: ubuntu-20.04
target: x86_64-unknown-linux-musl
bin: ${{ github.event.repository.name }}-linux-amd64
- os_name: Windows-x86_64
os: windows-latest
target: x86_64-pc-windows-msvc
bin: ${{ github.event.repository.name }}-amd64.exe
- os_name: macOS-x86_64
os: macOS-latest
target: x86_64-apple-darwin
bin: ${{ github.event.repository.name }}-darwin-amd64
- os_name: macOS-aarch64
os: macOS-latest
target: aarch64-apple-darwin
bin: ${{ github.event.repository.name }}-darwin-arm64
toolchain:
- stable
steps:
- uses: actions/checkout@v3
- name: Install Linux musl-tools
if: contains(matrix.platform.target, 'musl')
run: |
sudo apt-get install --yes --no-install-recommends musl-tools clang
sudo ln -s /usr/bin/g++ /usr/bin/musl-g++
- name: Build binary
uses: houseabsolute/actions-rust-cross@v0
with:
command: "build"
target: ${{ matrix.platform.target }}
toolchain: ${{ matrix.toolchain }}
args: "--locked --release"
strip: true
- name: Build x86_64 with docker
uses: docker/build-push-action@v5
if: matrix.platform.os_name != 'Linux-x86_64'
with:
context: .
file: ./musl.Dockerfile
push: false
platforms: linux/amd64
tags: ${{ vars.DOCKERHUB_USER }}/${{ github.event.repository.name }}:musl
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Create folder for musl binary
if: matrix.platform.os_name != 'Linux-x86_64'
run: |
mkdir -p target/x86_64-unknown-linux-musl/release
- uses: shrink/actions-docker-extract@v3
if: matrix.platform.os_name != 'Linux-x86_64'
id: extract
with:
image: ${{ vars.DOCKERHUB_USER }}/${{ github.event.repository.name }}:musl
path: /app/${{ github.event.repository.name }}
destination: target/x86_64-unknown-linux-musl/release/github.event.repository.name
- name: Rename binary (linux and macos)
run: mv target/${{ matrix.platform.target }}/release/${{ github.event.repository.name }} target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}
if: matrix.platform.os_name != 'Windows-x86_64'
- name: Rename binary (windows)
run: mv target/${{ matrix.platform.target }}/release/${{ github.event.repository.name }}.exe target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}
if: matrix.platform.os_name == 'Windows-x86_64'
- name: Generate SHA-256
run: shasum -a 256 target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }} | cut -d ' ' -f 1 > target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}.sha256
- name: Release binary and SHA-256 checksum to GitHub
uses: softprops/action-gh-release@v1
with:
files: |
target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}
target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }}.sha256
docker:
runs-on: ubuntu-latest
name: Build and push image
needs: build
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- run: docker context create ci
- run: docker context use ci
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
endpoint: ci
- name: Fetch latest release tag
id: latest-tag
run: |
LATEST_TAG=$(curl -s https://api.github.com/repos/${{ github.repository }}/releases/latest | jq -r .tag_name)
echo "Latest release tag is $LATEST_TAG"
echo "::set-output name=tag::$LATEST_TAG"
shell: bash
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
platforms: linux/amd64, linux/arm64
build-args: |
GITHUB_ORG=${{ github.repository_owner }}
GITHUB_REPO=${{ github.event.repository.name }}
tags: ${{ secrets.DOCKERHUB_ORGANISATION }}/${{ github.event.repository.name }}:${{ steps.latest-tag.outputs.tag }},${{ secrets.DOCKERHUB_ORGANISATION }}/${{ github.event.repository.name }}:latest
cache-from: type=gha
cache-to: type=gha,mode=max