Build tagged releases on Gitea (#79)
This commit is contained in:
178
.gitea/workflows/release.yml
Normal file
178
.gitea/workflows/release.yml
Normal file
@@ -0,0 +1,178 @@
|
||||
name: Tagged release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
|
||||
jobs:
|
||||
prepare-release:
|
||||
runs-on: linux-arm64
|
||||
outputs:
|
||||
release_id: ${{ steps.release.outputs.release_id }}
|
||||
steps:
|
||||
- name: Check out the tag
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Test release-note generation
|
||||
run: python3 .gitea/scripts/release.py test
|
||||
|
||||
- name: Create draft release
|
||||
id: release
|
||||
env:
|
||||
GITEA_API_URL: ${{ gitea.server_url }}/api/v1
|
||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||
GITEA_REF_NAME: ${{ gitea.ref_name }}
|
||||
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
||||
GITEA_SHA: ${{ gitea.sha }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: python3 .gitea/scripts/release.py prepare
|
||||
|
||||
build-unix:
|
||||
needs: prepare-release
|
||||
runs-on: linux-arm64
|
||||
container: ghcr.io/rust-cross/cargo-zigbuild@sha256:82af75c41958c2af2787e8bedd912da7678a9438937e223e9d83d006d747b38b
|
||||
steps:
|
||||
- name: Check out the tag
|
||||
env:
|
||||
GITEA_REF_NAME: ${{ gitea.ref_name }}
|
||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git init
|
||||
git -c http.extraHeader="Authorization: token $GITEA_TOKEN" fetch --depth=1 \
|
||||
"$GITEA_SERVER_URL/$GITEA_REPOSITORY.git" "refs/tags/$GITEA_REF_NAME"
|
||||
git checkout --detach FETCH_HEAD
|
||||
|
||||
- name: Build, package, and upload Unix releases
|
||||
env:
|
||||
GITEA_API_URL: ${{ gitea.server_url }}/api/v1
|
||||
GITEA_REF_NAME: ${{ gitea.ref_name }}
|
||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
RELEASE_ID: ${{ needs.prepare-release.outputs.release_id }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
version=$(printf '%s' "$GITEA_REF_NAME" | sed 's/[^A-Za-z0-9._-]/-/g')
|
||||
for build in \
|
||||
'aarch64-unknown-linux-gnu|aarch64-unknown-linux-gnu.2.28|linux-arm64' \
|
||||
'x86_64-unknown-linux-gnu|x86_64-unknown-linux-gnu.2.28|linux-x64' \
|
||||
'aarch64-apple-darwin|aarch64-apple-darwin|darwin-arm64'
|
||||
do
|
||||
IFS='|' read -r target build_target platform <<< "$build"
|
||||
cargo zigbuild --release --locked --target "$build_target" \
|
||||
--package ironstorage-cli \
|
||||
--package ironstorage-tui \
|
||||
--package ironstorage-desktop
|
||||
|
||||
cli="ironstorage-cli-${version}-${platform}"
|
||||
desktop="ironstorage-desktop-${version}-${platform}"
|
||||
mkdir -p "dist/$cli" "dist/$desktop"
|
||||
cp "target/$target/release/ironstorage" "dist/$cli/"
|
||||
cp "target/$target/release/ironstorage-tui" "dist/$cli/"
|
||||
cp "target/$target/release/ironstorage" "dist/$desktop/"
|
||||
cp "target/$target/release/ironstorage-tui" "dist/$desktop/"
|
||||
cp "target/$target/release/ironstorage-desktop" "dist/$desktop/"
|
||||
tar -C dist -czf "dist/${cli}.tar.gz" "$cli"
|
||||
tar -C dist -czf "dist/${desktop}.tar.gz" "$desktop"
|
||||
rm -r "dist/$cli" "dist/$desktop"
|
||||
|
||||
for asset in "dist/${cli}.tar.gz" "dist/${desktop}.tar.gz"; do
|
||||
name=$(basename "$asset")
|
||||
curl --fail --silent --show-error --retry 3 \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary "@$asset" \
|
||||
"$GITEA_API_URL/repos/$GITEA_REPOSITORY/releases/$RELEASE_ID/assets?name=$name"
|
||||
done
|
||||
done
|
||||
|
||||
build-windows:
|
||||
needs:
|
||||
- prepare-release
|
||||
- build-unix
|
||||
runs-on: linux-arm64
|
||||
container: messense/cargo-xwin@sha256:4696dd4e79edf8569fa99c4b06bd99273e0501c7adc983aa61d57945f795bef0
|
||||
steps:
|
||||
- name: Check out the tag
|
||||
env:
|
||||
GITEA_REF_NAME: ${{ gitea.ref_name }}
|
||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||
GITEA_SERVER_URL: ${{ gitea.server_url }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git init
|
||||
git -c http.extraHeader="Authorization: token $GITEA_TOKEN" fetch --depth=1 \
|
||||
"$GITEA_SERVER_URL/$GITEA_REPOSITORY.git" "refs/tags/$GITEA_REF_NAME"
|
||||
git checkout --detach FETCH_HEAD
|
||||
|
||||
- name: Install the repository Rust toolchain
|
||||
run: rustup toolchain install 1.92.0 --profile minimal --target x86_64-pc-windows-msvc
|
||||
|
||||
- name: Cross-build release binaries
|
||||
run: >-
|
||||
cargo +1.92.0 xwin build --release --locked
|
||||
--target x86_64-pc-windows-msvc
|
||||
--package ironstorage-cli
|
||||
--package ironstorage-tui
|
||||
--package ironstorage-desktop
|
||||
|
||||
- name: Package CLI, TUI, and desktop application
|
||||
env:
|
||||
TAG: ${{ gitea.ref_name }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
version=$(printf '%s' "$TAG" | sed 's/[^A-Za-z0-9._-]/-/g')
|
||||
cli="ironstorage-cli-${version}-windows-x64"
|
||||
desktop="ironstorage-desktop-${version}-windows-x64"
|
||||
release=target/x86_64-pc-windows-msvc/release
|
||||
mkdir -p "dist/$cli" "dist/$desktop"
|
||||
cp "$release/ironstorage.exe" "$release/ironstorage-tui.exe" "dist/$cli/"
|
||||
cp "$release/ironstorage.exe" "$release/ironstorage-tui.exe" \
|
||||
"$release/ironstorage-desktop.exe" "dist/$desktop/"
|
||||
tar -C dist -czf "dist/${cli}.tar.gz" "$cli"
|
||||
tar -C dist -czf "dist/${desktop}.tar.gz" "$desktop"
|
||||
rm -r "dist/$cli" "dist/$desktop"
|
||||
|
||||
- name: Upload release packages
|
||||
env:
|
||||
GITEA_API_URL: ${{ gitea.server_url }}/api/v1
|
||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
RELEASE_ID: ${{ needs.prepare-release.outputs.release_id }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
for asset in dist/*.tar.gz; do
|
||||
name=$(basename "$asset")
|
||||
curl --fail --silent --show-error --retry 3 \
|
||||
-H "Authorization: token $GITEA_TOKEN" \
|
||||
-H "Content-Type: application/octet-stream" \
|
||||
--data-binary "@$asset" \
|
||||
"$GITEA_API_URL/repos/$GITEA_REPOSITORY/releases/$RELEASE_ID/assets?name=$name"
|
||||
done
|
||||
|
||||
publish-release:
|
||||
needs:
|
||||
- prepare-release
|
||||
- build-unix
|
||||
- build-windows
|
||||
runs-on: linux-arm64
|
||||
steps:
|
||||
- name: Check out the tag
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Publish complete release
|
||||
env:
|
||||
GITEA_API_URL: ${{ gitea.server_url }}/api/v1
|
||||
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
RELEASE_ID: ${{ needs.prepare-release.outputs.release_id }}
|
||||
run: python3 .gitea/scripts/release.py publish
|
||||
Reference in New Issue
Block a user