-
Notifications
You must be signed in to change notification settings - Fork 4
180 lines (152 loc) · 7.15 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
name: Ahnlich AI and DB Release
on:
release:
types: [published]
permissions:
contents: write
jobs:
prebuild_preparation:
name: Get Binary Type
runs-on: ubuntu-latest
outputs:
bin_name: ${{ steps.get_binary_type.outputs.BIN_NAME }}
bin_suffix: ${{ steps.get_binary_type.outputs.BIN_SUFFIX }}
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: "Get Binary Type"
id: get_binary_type
run: |
cd ${{github.workspace}}
echo ${{ github.event.release.tag_name }}
value=$(echo "${{ github.event.release.tag_name }}" | cut -d'/' -f2)
echo "$value"
echo "BIN_SUFFIX=${value}" >> $GITHUB_OUTPUT
echo "BIN_NAME=ahnlich-${value}" >> $GITHUB_OUTPUT
build_linux_binaries_and_publish:
needs: prebuild_preparation
name: Build Linux Binaries
runs-on: ubuntu-latest
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: Get Cargo toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.81.0
- name: Build Linux Release for ${{ needs.prebuild_preparation.outputs.bin_name }}
working-directory: ./ahnlich
run: |
cargo build --release --bin ${{ needs.prebuild_preparation.outputs.bin_name }}
tar -cvzf linux-${{ needs.prebuild_preparation.outputs.bin_name }}.tar.gz -C target/release ${{ needs.prebuild_preparation.outputs.bin_name }}
gh release upload ${{github.event.release.tag_name}} linux-${{ needs.prebuild_preparation.outputs.bin_name }}.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
shell: bash
build_macos_darwin_binaries_and_publish:
needs: prebuild_preparation
name: Build MacOs Darwin Binaries
runs-on: macos-latest
outputs:
bin_name: ${{ needs.prebuild_preparation.outputs.bin_name }}
bin_suffix: ${{ steps.get_binary_type.outputs.BIN_SUFFIX }}
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: Build Aarch64 Darwin Release for ${{ needs.prebuild_preparation.outputs.bin_name }}
working-directory: ./ahnlich
run: |
cargo build --release --target aarch64-apple-darwin --bin ${{ needs.prebuild_preparation.outputs.bin_name }}
tar -cvzf aarch64-darwin-${{ needs.prebuild_preparation.outputs.bin_name }}.tar.gz -C target/aarch64-apple-darwin/release ${{ needs.prebuild_preparation.outputs.bin_name }}
gh release upload ${{github.event.release.tag_name}} aarch64-darwin-${{ needs.prebuild_preparation.outputs.bin_name }}.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
shell: bash
build_macos_x86_64_binaries_and_publish:
needs: prebuild_preparation
name: Build MacOs x86_64 Binaries
runs-on: macos-13
steps:
- name: "Checkout"
uses: actions/checkout@v4
- name: Get Cargo toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.81.0
- name: Build x86_64 Apple Darwin Release for ${{ needs.prebuild_preparation.outputs.bin_name }}
working-directory: ./ahnlich
run: |
cargo build --release --target x86_64-apple-darwin --bin ${{ needs.prebuild_preparation.outputs.bin_name }}
tar -cvzf x86_64-apple-darwin-${{ needs.prebuild_preparation.outputs.bin_name }}.tar.gz -C target/x86_64-apple-darwin/release ${{ needs.prebuild_preparation.outputs.bin_name }}
gh release upload ${{github.event.release.tag_name}} x86_64-apple-darwin-${{ needs.prebuild_preparation.outputs.bin_name }}.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
shell: bash
push_to_registries:
needs: prebuild_preparation
name: Push Docker image to multiple registries
runs-on: ubuntu-latest
if: ${{needs.prebuild_preparation.outputs.bin_name != 'ahnlich-cli'}}
permissions:
packages: write
contents: read
attestations: write
id-token: write
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: Cache Docker images
uses: ScribeMD/[email protected]
with:
key: ${{ runner.os }}-cargo-${{ hashFiles('ahnlich/Cargo.lock') }}
- name: Set Port Based on Bin Name
id: set_port
run: |
if [ "${{ needs.prebuild_preparation.outputs.bin_name }}" == "ahnlich-db" ]; then
echo "DEFAULT_PORT=1369" >> $GITHUB_ENV
echo "DESCRIPTION=Ahnlich DB" >> $GITHUB_ENV
else
echo "DEFAULT_PORT=1370" >> $GITHUB_ENV
echo "DESCRIPTION=Ahnlich AI" >> $GITHUB_ENV
fi
- name: Extract version number from tag
id: extract_version
working-directory: ./ahnlich
run: |
# Extract only the numerical version part from the tag
VERSION=$(make workspace-crate-version CRATE_NAME=${{ needs.prebuild_preparation.outputs.bin_suffix }} | tail -n 1)
echo $VERSION
echo "BIN_VERSION=$VERSION" >> $GITHUB_ENV
- name: Log in to the Container registry
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GH_GCR_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ghcr.io/${{ github.repository_owner }}/${{needs.prebuild_preparation.outputs.bin_name}}
tags: |
type=schedule
type=semver,pattern={{version}},value=v${{env.BIN_VERSION}}
labels: |
org.opencontainers.image.description=${{ env.DESCRIPTION }}
- name: Build and push Docker images
id: push
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85
with:
context: ./ahnlich
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
AHNLICH_BIN=${{ needs.prebuild_preparation.outputs.bin_name}}
DEFAULT_PORT=${{env.DEFAULT_PORT}}
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-name: ghcr.io/${{ github.repository_owner }}/${{needs.prebuild_preparation.outputs.bin_name}}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true