forked from xline-kv/Xline
-
Notifications
You must be signed in to change notification settings - Fork 0
157 lines (138 loc) · 4.68 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Release
on:
push:
tags:
- "v*"
env:
CI_RUST_TOOLCHAIN: 1.74.0
IMAGE_ID: ghcr.io/xline-kv/xline
jobs:
create_release:
name: Create Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Create Release
id: create_release
uses: actions/create-release@v1.1.4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
publish_release:
name: Publish Release
needs: create_release
runs-on: ${{ matrix.job.os }}
outputs:
app_version: ${{ steps.generate_app_version.outputs.app_version }}
strategy:
fail-fast: false
matrix:
job:
- os: ubuntu-latest
platform: linux/amd64
target: x86_64-unknown-linux-gnu
cross_image: x86_64-linux-gnu
- os: ubuntu-latest
platform: linux/arm64
target: aarch64-unknown-linux-gnu
cross_image: aarch64-linux-gnu
- os: macos-latest
platform: darwin/amd64
target: x86_64-apple-darwin
- os: macos-latest
platform: darwin/arm64
target: aarch64-apple-darwin
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Generate App Version
id: generate_app_version
run: echo app_version=`git describe --tags --always` >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
if: matrix.job.cross_image
uses: docker/setup-buildx-action@v3
- name: Setup Custom Image for ${{ matrix.job.cross_image }}
if: matrix.job.cross_image
uses: docker/build-push-action@v5
with:
context: ci/cross
file: ci/cross/Dockerfile.${{ matrix.job.target }}
tags: ${{ matrix.job.cross_image }}:latest
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Install Packages (macOS)
if: matrix.job.os == 'macos-latest'
run: |
ci/scripts/install_macos_deps.sh
- name: Install Toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: ${{ env.CI_RUST_TOOLCHAIN }}
target: ${{ matrix.job.target }}
- name: Install cross from binary
uses: taiki-e/install-action@cross
- name: Build Xline Binary
run: |
cross build --target ${{ matrix.job.target }} --release
- name: Upload Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.create_release.outputs.upload_url }}
asset_path: ./target/${{ matrix.job.target }}/release/xline
asset_name: xline-${{ matrix.job.target }}
asset_content_type: application/octet-stream
# Build docker image across multiple runners
- name: Move Cross-compiled Binary
if: startsWith(matrix.job.platform, 'linux/')
run: |
mv ./target/${{ matrix.job.target }}/release/xline ./scripts
mv ./target/${{ matrix.job.target }}/release/benchmark ./scripts
- name: Set up QEMU
if: startsWith(matrix.job.platform, 'linux/')
uses: docker/setup-qemu-action@v3
- name: Login to GHCR
if: startsWith(matrix.job.platform, 'linux/')
uses: docker/login-action@v3
with:
registry: ghcr.io
username: xline-kv
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker Image
if: startsWith(matrix.job.platform, 'linux/')
id: build_image
uses: docker/build-push-action@v5
with:
context: ./scripts
platforms: ${{ matrix.job.platform }}
outputs: type=image,name=${{ env.IMAGE_ID }},push-by-digest=true,name-canonical=true,push=true
- name: Export Digest
if: startsWith(matrix.job.platform, 'linux/')
run: |
mkdir -p /tmp/digests
digest="${{ steps.build_image.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload Digest
uses: actions/upload-artifact@v4
if: startsWith(matrix.job.platform, 'linux/')
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
merge_image:
needs: publish_release
uses: ./.github/workflows/merge_image.yml
secrets: inherit
with:
app_version: ${{ needs.publish_release.outputs.app_version }}