development
yml 153 lines 4.43 KB
Raw
1 name: GitHub Release
2
3 on:
4 workflow_dispatch:
5 inputs:
6 tag:
7 description: "Release tag (e.g. v0.2.0)"
8 required: true
9
10 # One release per tag at a time, and never cancelled: a half-built release
11 # has to finish or fail on its own. A second dispatch for the same tag waits.
12 concurrency:
13 group: release-github-${{ github.event.inputs.tag || github.ref }}
14 cancel-in-progress: false
15
16 permissions:
17 contents: write
18
19 env:
20 PROJECT_NAME: asc
21 CARGO_TERM_COLOR: always
22
23 jobs:
24 build:
25 name: Build binary (${{ matrix.name }})
26 runs-on: ${{ matrix.runner }}
27
28 strategy:
29 fail-fast: false
30 matrix:
31 include:
32 - name: linux-amd64
33 runner: ubuntu-latest
34 target: x86_64-unknown-linux-gnu
35 - name: linux-arm64
36 runner: ubuntu-24.04-arm
37 target: aarch64-unknown-linux-gnu
38 - name: win-amd64
39 runner: windows-latest
40 target: x86_64-pc-windows-msvc
41 - name: win-arm64
42 runner: windows-latest
43 target: aarch64-pc-windows-msvc
44 - name: macos-amd64
45 runner: macos-15-intel
46 target: x86_64-apple-darwin
47 - name: macos-arm64
48 runner: macos-latest
49 target: aarch64-apple-darwin
50
51 steps:
52 - name: Checkout
53 uses: actions/checkout@v6
54 with:
55 ref: ${{ github.event.inputs.tag || github.ref }}
56
57 - name: Set the release version
58 shell: bash
59 run: |
60 if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
61 release_version="${GITHUB_REF_NAME#v}"
62 else
63 release_version="${{ github.event.inputs.tag }}"
64 release_version="${release_version#v}"
65 fi
66
67 echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
68
69 - name: Install toolkit
70 uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
71 with:
72 toolchain: stable
73 targets: ${{ matrix.target }}
74
75 - name: Setup Rust cache
76 uses: Swatinem/rust-cache@v2
77 with:
78 key: github-${{ matrix.target }}
79
80 - name: Build binary
81 shell: bash
82 run: cargo build --locked --release --target ${{ matrix.target }} --package smbcloud-ascapi-cli
83
84 - name: Package binary
85 shell: bash
86 run: |
87 BIN_SUFFIX=""
88 if [[ "${{ matrix.runner }}" == "windows-latest" ]]; then
89 BIN_SUFFIX=".exe"
90 fi
91
92 BIN_OUTPUT="target/${{ matrix.target }}/release/${PROJECT_NAME}${BIN_SUFFIX}"
93 BIN_RELEASE="${PROJECT_NAME}-${{ matrix.name }}${BIN_SUFFIX}"
94
95 mkdir -p ./release
96 mv "${BIN_OUTPUT}" "./release/${BIN_RELEASE}"
97
98 # Windows runners use bash from Git for Windows, which has sha256sum;
99 # macOS only has shasum.
100 - name: Checksum release assets
101 shell: bash
102 run: |
103 cd release
104 for asset in *; do
105 case "${asset}" in *.sha256) continue ;; esac
106
107 if command -v sha256sum >/dev/null 2>&1; then
108 sha256sum "${asset}" | awk '{print $1}' > "${asset}.sha256"
109 else
110 shasum -a 256 "${asset}" | awk '{print $1}' > "${asset}.sha256"
111 fi
112
113 echo "${asset}: $(cat "${asset}.sha256")"
114 done
115
116 - name: Upload binary artifact
117 uses: actions/upload-artifact@v7
118 with:
119 name: binary-${{ matrix.name }}
120 path: release/*
121
122 release:
123 name: Create GitHub Release
124 needs: build
125 runs-on: ubuntu-latest
126 if: github.ref_type == 'tag' || github.event_name == 'workflow_dispatch'
127
128 steps:
129 - name: Resolve tag
130 id: tag
131 shell: bash
132 run: |
133 if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
134 echo "tag=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT"
135 else
136 echo "tag=${{ github.ref_name }}" >> "$GITHUB_OUTPUT"
137 fi
138
139 - name: Download binary artifacts
140 uses: actions/download-artifact@v7
141 with:
142 pattern: "binary-*"
143 path: release
144 merge-multiple: true
145
146 - name: Release
147 uses: softprops/action-gh-release@v2
148 with:
149 tag_name: ${{ steps.tag.outputs.tag }}
150 files: release/*
151 # Build the notes from the PRs since the previous tag, the same
152 # format as the "Generate release notes" button on the web UI.
153 generate_release_notes: true