-
Notifications
You must be signed in to change notification settings - Fork 1
167 lines (149 loc) · 5.17 KB
/
release.yml
File metadata and controls
167 lines (149 loc) · 5.17 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
name: Release
on:
push:
tags:
- "v*"
permissions:
contents: read
concurrency:
group: release-${{ github.ref_name }}
cancel-in-progress: false
jobs:
verify_tag_on_main:
name: Verify Tagged Commit
runs-on: ubuntu-24.04
outputs:
tag_commit: ${{ steps.resolve_tag.outputs.sha }}
steps:
- name: Check out repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Resolve tagged commit
id: resolve_tag
shell: bash
run: |
set -euo pipefail
tag_commit="$(git rev-list -n 1 "$GITHUB_REF_NAME")"
echo "sha=$tag_commit" >> "$GITHUB_OUTPUT"
- name: Ensure tagged commit is on origin/main
shell: bash
run: |
set -euo pipefail
git fetch --no-tags --prune origin +refs/heads/main:refs/remotes/origin/main
if ! git merge-base --is-ancestor "${{ steps.resolve_tag.outputs.sha }}" origin/main; then
echo "::error::Tag ${GITHUB_REF_NAME} points to commit ${{ steps.resolve_tag.outputs.sha }}, which is not reachable from origin/main."
exit 1
fi
build:
name: Build ${{ matrix.target }}
needs: verify_tag_on_main
runs-on: ${{ matrix.runs_on }}
strategy:
fail-fast: false
matrix:
include:
- runs_on: ubuntu-24.04
target: x86_64-unknown-linux-gnu
archive_ext: tar.gz
- runs_on: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
archive_ext: tar.gz
- runs_on: windows-2025
target: x86_64-pc-windows-msvc
archive_ext: zip
- runs_on: windows-11-arm
target: aarch64-pc-windows-msvc
archive_ext: zip
- runs_on: macos-15-intel
target: x86_64-apple-darwin
archive_ext: tar.gz
- runs_on: macos-15
target: aarch64-apple-darwin
archive_ext: tar.gz
steps:
- name: Check out repository
uses: actions/checkout@v5
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Restore Cargo cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.runs_on }}-${{ matrix.target }}
- name: Build release binary
run: cargo build --locked --release --target ${{ matrix.target }}
- name: Package release archive on Unix
if: runner.os != 'Windows'
shell: bash
run: |
set -euo pipefail
archive="dagger-${GITHUB_REF_NAME}-${{ matrix.target }}.tar.gz"
package_dir="dist/package"
mkdir -p "$package_dir"
cp "target/${{ matrix.target }}/release/dgr" "$package_dir/dgr"
cp README.md "$package_dir/README.md"
tar -C "$package_dir" -czf "dist/$archive" dgr README.md
- name: Package release archive on Windows
if: runner.os == 'Windows'
shell: pwsh
run: |
$packageDir = Join-Path "dist" "package"
New-Item -ItemType Directory -Path $packageDir -Force | Out-Null
Copy-Item "target/${{ matrix.target }}/release/dgr.exe" (Join-Path $packageDir "dgr.exe")
Copy-Item "README.md" (Join-Path $packageDir "README.md")
$archive = Join-Path "dist" "dagger-$env:GITHUB_REF_NAME-${{ matrix.target }}.zip"
Compress-Archive -Path (Join-Path $packageDir "*") -DestinationPath $archive -Force
- name: Upload release artifact
uses: actions/upload-artifact@v6
with:
name: release-${{ matrix.target }}
path: dist/dagger-${{ github.ref_name }}-${{ matrix.target }}.${{ matrix.archive_ext }}
if-no-files-found: error
publish:
name: Publish GitHub Release
needs: build
runs-on: ubuntu-24.04
permissions:
contents: write
steps:
- name: Download build artifacts
uses: actions/download-artifact@v8
with:
pattern: release-*
merge-multiple: true
path: release-artifacts
- name: Generate checksums
shell: bash
run: |
set -euo pipefail
cd release-artifacts
shopt -s nullglob
files=(dagger-*)
if [ "${#files[@]}" -eq 0 ]; then
echo "No release artifacts were downloaded." >&2
exit 1
fi
printf '%s\0' "${files[@]}" | sort -z | xargs -0 sha256sum > SHA256SUMS
- name: Create or update release
shell: bash
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
run: |
set -euo pipefail
tag="${GITHUB_REF_NAME}"
if gh release view "$tag" >/dev/null 2>&1; then
echo "Release $tag already exists."
if [[ "$tag" == *-* ]]; then
gh release edit "$tag" --prerelease
fi
else
create_args=(release create "$tag" --verify-tag --generate-notes)
if [[ "$tag" == *-* ]]; then
create_args+=(--prerelease)
fi
gh "${create_args[@]}"
fi
gh release upload "$tag" release-artifacts/* --clobber