-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (143 loc) · 5.2 KB
/
release-cli.yml
File metadata and controls
163 lines (143 loc) · 5.2 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
name: Release CLI
on:
# Trigger when a release with cli-* tag is published via GitHub UI or API
release:
types: [published]
# Allow manual trigger (useful when release already exists without binaries)
workflow_dispatch:
inputs:
tag:
description: 'Release tag (e.g., cli-1.1.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 }}
should_run: ${{ steps.resolve.outputs.should_run }}
steps:
- name: Resolve tag and version
id: resolve
shell: bash
run: |
# Determine the tag from the trigger source
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ github.event.inputs.tag }}"
else
TAG="${{ github.event.release.tag_name }}"
fi
# Only process cli-* tags
if [[ "$TAG" != cli-* ]]; then
echo "Skipping: tag '$TAG' is not a CLI release"
echo "should_run=false" >> "$GITHUB_OUTPUT"
exit 0
fi
VERSION="${TAG#cli-}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "should_run=true" >> "$GITHUB_OUTPUT"
echo "Building CLI $VERSION from tag $TAG"
build-cli:
name: Build CLI (${{ matrix.target }})
needs: [resolve-version]
if: needs.resolve-version.outputs.should_run == 'true'
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@v5
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@v5
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@v5
- name: Download all artifacts
uses: actions/download-artifact@v5
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: Upload to existing release or create new one
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
TAG="${{ needs.resolve-version.outputs.tag }}"
VERSION="${{ needs.resolve-version.outputs.version }}"
# Check if release already exists
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 \
release/*
fi