Repository navigation
146 lines (134 loc) · 5.36 KB
/
Copy pathrelease-cli.yml
File metadata and controls
146 lines (134 loc) · 5.36 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
name: 'Publish CLI Releases'
on:
push:
tags:
- 'cli-v*'
workflow_dispatch:
jobs:
create-cli-release:
permissions:
contents: write
runs-on: ubuntu-22.04
outputs:
release_id: ${{ steps.create_release.outputs.release_id }}
is_prerelease: ${{ steps.release_gate.outputs.is_prerelease }}
steps:
- name: Validate Tag & Determine CLI Release Mode
id: release_gate
shell: bash
run: |
if [[ ! "${{ github.ref }}" =~ ^refs/tags/cli-v[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$ ]]; then
echo "Error: CLI release workflow must run on a valid cli-vX.Y.Z tag (got '${{ github.ref }}')."
exit 1
fi
if [[ "${{ github.ref }}" =~ ^refs/tags/cli-v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
echo "CLI Release Mode: STABLE RELEASE (${{ github.ref_name }})"
else
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
echo "CLI Release Mode: PRE-RELEASE (${{ github.ref_name }})"
fi
- name: Create Single Draft CLI Release
id: create_release
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CLEAN_VERSION="${GITHUB_REF_NAME#cli-}"
RELEASE_ID=$(gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
"/repos/${{ github.repository }}/releases" \
-f tag_name="${{ github.ref_name }}" \
-f name="Ombracrypt CLI ${CLEAN_VERSION}" \
-f body="Automated cross-platform CLI release binaries (Linux x86_64, Windows x86_64, macOS arm64 & x86_64) with SHA-256 checksums." \
-F draft=true \
-F prerelease=${{ steps.release_gate.outputs.is_prerelease }} \
--jq '.id')
echo "Created Draft CLI Release ID: ${RELEASE_ID}"
echo "release_id=${RELEASE_ID}" >> "$GITHUB_OUTPUT"
build-and-attach-cli:
needs: create-cli-release
permissions:
contents: write
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu
artifact_suffix: linux-x86_64
ext: tar.gz
- os: windows-latest
target: x86_64-pc-windows-msvc
artifact_suffix: windows-x86_64
ext: zip
- os: macos-latest
target: aarch64-apple-darwin
artifact_suffix: macos-aarch64
ext: tar.gz
- os: macos-latest
target: x86_64-apple-darwin
artifact_suffix: macos-x86_64
ext: tar.gz
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup Rust Stable
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Cache Cargo Build Artifacts
uses: Swatinem/rust-cache@v2
- name: Build CLI Binary (${{ matrix.target }})
run: cargo build --release --locked -p ombracrypt-cli --target ${{ matrix.target }}
- name: Package & Hash Archive (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
set -euo pipefail
BIN_PATH="target/${{ matrix.target }}/release/ombracrypt"
test -x "${BIN_PATH}"
mkdir -p dist
ARCHIVE="ombracrypt-${{ github.ref_name }}-${{ matrix.artifact_suffix }}.tar.gz"
cp "${BIN_PATH}" dist/ombracrypt
cp apps/cli/README.md dist/README.md
cp LICENSE dist/LICENSE
tar -czf "${ARCHIVE}" -C dist ombracrypt README.md LICENSE
if command -v sha256sum >/dev/null 2>&1; then
sha256sum "${ARCHIVE}" > "${ARCHIVE}.sha256"
else
shasum -a 256 "${ARCHIVE}" > "${ARCHIVE}.sha256"
fi
test -s "${ARCHIVE}"
test -s "${ARCHIVE}.sha256"
- name: Package & Hash Archive (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$binPath = "target/${{ matrix.target }}/release/ombracrypt.exe"
if (-not (Test-Path $binPath)) {
Write-Error "Compiled CLI binary not found at $binPath"
exit 1
}
New-Item -ItemType Directory -Force -Path dist | Out-Null
$archive = "ombracrypt-${{ github.ref_name }}-${{ matrix.artifact_suffix }}.zip"
Copy-Item $binPath -Destination "dist/ombracrypt.exe"
Copy-Item "apps/cli/README.md" -Destination "dist/README.md"
Copy-Item "LICENSE" -Destination "dist/LICENSE"
Compress-Archive -Path dist/* -DestinationPath $archive
$hash = (Get-FileHash -Algorithm SHA256 $archive).Hash.ToLower()
"$hash $archive" | Out-File -Encoding ascii -FilePath "$archive.sha256"
if (-not (Test-Path $archive) -or -not (Test-Path "$archive.sha256")) {
Write-Error "Failed to generate release archive or SHA-256 checksum."
exit 1
}
- name: Attach Archive & Checksum to Draft Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
ARCHIVE="ombracrypt-${{ github.ref_name }}-${{ matrix.artifact_suffix }}.${{ matrix.ext }}"
gh release upload "${{ github.ref_name }}" "${ARCHIVE}" "${ARCHIVE}.sha256" --clobber