-
Notifications
You must be signed in to change notification settings - Fork 0
190 lines (165 loc) · 5.85 KB
/
release-cli.yml
File metadata and controls
190 lines (165 loc) · 5.85 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
name: Release CLI
on:
push:
tags:
- 'cli-*'
# Allow manual trigger (useful for re-runs or when tag already exists)
workflow_dispatch:
inputs:
tag:
description: 'Release tag (e.g., cli-3.2.0)'
required: true
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
jobs:
# Determine the tag and version to build
resolve-version:
name: Resolve version
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.resolve.outputs.tag }}
version: ${{ steps.resolve.outputs.version }}
steps:
- name: Resolve tag and version
id: resolve
shell: bash
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ github.event.inputs.tag }}"
else
TAG="${{ github.ref_name }}"
fi
if [[ "$TAG" != cli-* ]]; then
echo "ERROR: tag '$TAG' is not a CLI release (must start with cli-)"
exit 1
fi
VERSION="${TAG#cli-}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Building CLI $VERSION from tag $TAG"
build-cli:
name: Build CLI (${{ matrix.target }})
needs: [resolve-version]
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
archive: tar.gz
- target: x86_64-apple-darwin
os: macos-latest
archive: tar.gz
- target: aarch64-apple-darwin
os: macos-latest
archive: tar.gz
- target: x86_64-pc-windows-msvc
os: windows-latest
archive: zip
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.resolve-version.outputs.tag }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install OpenSSL (Linux)
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y libssl-dev pkg-config
- name: Verify Cargo.toml version matches tag
shell: bash
run: |
CARGO_VERSION=$(grep '^version' cli/Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
TAG_VERSION="${{ needs.resolve-version.outputs.version }}"
if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
echo "ERROR: Cargo.toml version ($CARGO_VERSION) does not match tag version ($TAG_VERSION)"
exit 1
fi
- name: Build release binary
run: cargo build --release --manifest-path cli/Cargo.toml --target ${{ matrix.target }}
- name: Package (Unix)
if: matrix.archive == 'tar.gz'
shell: bash
run: |
BINARY=cli/target/${{ matrix.target }}/release/devtrail
ARCHIVE=devtrail-cli-v${{ needs.resolve-version.outputs.version }}-${{ matrix.target }}.tar.gz
tar czf "$ARCHIVE" -C "$(dirname "$BINARY")" "$(basename "$BINARY")"
echo "ARCHIVE=$ARCHIVE" >> "$GITHUB_ENV"
- name: Package (Windows)
if: matrix.archive == 'zip'
shell: bash
run: |
BINARY=cli/target/${{ matrix.target }}/release/devtrail.exe
ARCHIVE=devtrail-cli-v${{ needs.resolve-version.outputs.version }}-${{ matrix.target }}.zip
cp "$BINARY" devtrail.exe
7z a "$ARCHIVE" devtrail.exe
echo "ARCHIVE=$ARCHIVE" >> "$GITHUB_ENV"
- name: Upload binary artifact
uses: actions/upload-artifact@v7
with:
name: cli-${{ matrix.target }}
path: ${{ env.ARCHIVE }}
upload-to-release:
name: Upload binaries to release
needs: [resolve-version, build-cli]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Download all artifacts
uses: actions/download-artifact@v8
with:
path: release-artifacts
- name: Collect release files
run: |
mkdir -p release
find release-artifacts -type f \( -name "*.zip" -o -name "*.tar.gz" \) -exec cp {} release/ \;
ls -la release/
- name: Create or update GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
TAG="${{ needs.resolve-version.outputs.tag }}"
VERSION="${{ needs.resolve-version.outputs.version }}"
if gh release view "$TAG" > /dev/null 2>&1; then
echo "Release $TAG exists, uploading binaries..."
gh release upload "$TAG" release/* --clobber
else
echo "Creating release $TAG..."
gh release create "$TAG" \
--title "DevTrail CLI $VERSION" \
--generate-notes \
--latest \
release/*
fi
- name: Delete previous CLI releases
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
CURRENT_TAG="${{ needs.resolve-version.outputs.tag }}"
gh release list --json tagName --jq '.[].tagName' | while read -r tag; do
if [[ "$tag" == cli-* && "$tag" != "$CURRENT_TAG" ]]; then
echo "Deleting old release $tag..."
gh release delete "$tag" --yes --cleanup-tag
fi
done
publish-crate:
name: Publish to crates.io
needs: [resolve-version, upload-to-release]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
ref: ${{ needs.resolve-version.outputs.tag }}
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Copy README into crate directory
run: cp README.md cli/README.md
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: cargo publish --manifest-path cli/Cargo.toml --allow-dirty