-
-
Notifications
You must be signed in to change notification settings - Fork 1
170 lines (152 loc) · 5.96 KB
/
release.yml
File metadata and controls
170 lines (152 loc) · 5.96 KB
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
name: Create Release
on:
workflow_dispatch:
push:
tags:
- "v*"
permissions:
contents: read
jobs:
call_tests:
uses: ./.github/workflows/tests.yml
create-release:
name: Create Release
runs-on: ubuntu-latest
# Try to publish only if the tests pass
needs: call_tests
if: success()
permissions:
contents: write
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create temporary tag for draft
# Only create a temporary tag when triggered by a push (don't create tags for manual workflow_dispatch runs)
if: github.event_name == 'push' && github.ref_type != 'tag'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
TAG_NAME="draft-${{ github.ref_name }}-$(date +%s)"
echo "DRAFT_TAG=$TAG_NAME" >> $GITHUB_ENV
git tag $TAG_NAME
git push origin $TAG_NAME
- name: Set release tag name
run: |
# Prefer an existing tag if this run was for a tag. If we created a DRAFT_TAG (on push), use it.
# For manual runs (workflow_dispatch) we intentionally do NOT create a git tag; instead use
# a synthetic tag name based on the workflow run id so the release has a stable name.
if [ "${{ github.ref_type }}" = "tag" ]; then
echo "RELEASE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
elif [ -n "${{ env.DRAFT_TAG }}" ]; then
echo "RELEASE_TAG=${{ env.DRAFT_TAG }}" >> $GITHUB_ENV
else
echo "RELEASE_TAG=manual-${{ github.run_id }}" >> $GITHUB_ENV
fi
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.RELEASE_TAG }}
release_name: Release ${{ env.RELEASE_TAG }}
draft: ${{ github.ref_type != 'tag' }}
prerelease: true
build-and-upload:
name: Build and Upload
needs: create-release
runs-on: ${{ matrix.os }}
permissions:
contents: write
strategy:
matrix:
include:
- os: ubuntu-latest
target: x86_64-linux-gnu
artifact_name: zigformer-linux-x86_64.zip
asset_content_type: application/zip
- os: ubuntu-latest
target: aarch64-linux-gnu
artifact_name: zigformer-linux-aarch64.zip
asset_content_type: application/zip
- os: macos-latest
target: aarch64-macos # Apple Silicon (ARM64)
artifact_name: zigformer-macos-aarch64.zip
asset_content_type: application/zip
- os: macos-latest
target: x86_64-macos # Intel
artifact_name: zigformer-macos-x86_64.zip
asset_content_type: application/zip
- os: windows-latest
target: x86_64-windows-msvc
artifact_name: zigformer-windows-x86_64.zip
asset_content_type: application/zip
- os: windows-latest
target: aarch64-windows-msvc
artifact_name: zigformer-windows-aarch64.zip
asset_content_type: application/zip
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Install Zig
uses: goto-bus-stop/setup-zig@v2
with:
version: "0.15.2"
- name: Build the binary
run: zig build -Doptimize=ReleaseSmall -Dtarget=${{ matrix.target }}
- name: Verify built binary exists (Unix)
if: runner.os != 'Windows'
run: |
if [ ! -f zig-out/bin/zigformer-cli ]; then
echo "ERROR: built binary zig-out/bin/zigformer-cli not found"
ls -l zig-out/bin || true
exit 1
fi
if [ ! -f zig-out/bin/zigformer-gui ]; then
echo "ERROR: built binary zig-out/bin/zigformer-gui not found"
ls -l zig-out/bin || true
exit 1
fi
- name: Verify built binary exists (Windows)
if: runner.os == 'Windows'
run: |
if (!(Test-Path "zig-out\\bin\\zigformer-cli.exe")) {
Write-Host 'ERROR: built binary zig-out\\bin\\zigformer-cli.exe not found'
dir zig-out\\bin
exit 1
}
if (!(Test-Path "zig-out\\bin\\zigformer-gui.exe")) {
Write-Host 'ERROR: built binary zig-out\\bin\\zigformer-gui.exe not found'
dir zig-out\\bin
exit 1
}
- name: Prepare artifact for Linux/macOS
if: runner.os != 'Windows'
run: |
RELEASE_DIR="release-${{ matrix.target }}-${{ github.run_id }}"
mkdir -p "$RELEASE_DIR"
mv zig-out/bin/zigformer-cli "$RELEASE_DIR"/
mv zig-out/bin/zigformer-gui "$RELEASE_DIR"/
# Create a zip of the release contents (avoid nesting an extra top-level directory)
(cd "$RELEASE_DIR" && zip -r "../${{ matrix.artifact_name }}" .)
- name: Prepare artifact for Windows
if: runner.os == 'Windows'
run: |
$env:RELEASE_DIR = "release-${{ matrix.target }}-${{ github.run_id }}"
New-Item -ItemType Directory -Path $env:RELEASE_DIR -Force | Out-Null
Move-Item zig-out\bin\zigformer-cli.exe $env:RELEASE_DIR\
Move-Item zig-out\bin\zigformer-gui.exe $env:RELEASE_DIR\
Compress-Archive -Path "$env:RELEASE_DIR\*" -DestinationPath ${{ matrix.artifact_name }}
- name: 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: ./${{ matrix.artifact_name }}
asset_name: ${{ matrix.artifact_name }}
asset_content_type: ${{ matrix.asset_content_type }}