From 697979bd994e8979ab4e1f1d2d875ed8ca968828 Mon Sep 17 00:00:00 2001 From: figsoda Date: Sun, 20 Nov 2022 15:42:08 -0500 Subject: [PATCH] ci: automatically create github releases on tags --- .github/workflows/build-and-test.yml | 23 +++++++++++++++++++ .github/workflows/manual-release.yml | 33 ++++++++++++++++++++++++++++ release-helper.sh | 21 ------------------ scripts/package-release-assets.sh | 22 +++++++++++++++++++ 4 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/manual-release.yml delete mode 100644 release-helper.sh create mode 100755 scripts/package-release-assets.sh diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 0ae3b2a..de41f52 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -111,3 +111,26 @@ jobs: rustup toolchain install nightly --profile minimal -c rustfmt cargo +stable clippy -- -D warnings cargo +nightly fmt -- --check + + github-release: + name: github-release + runs-on: ubuntu-latest + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + needs: build + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Download artifacts + uses: dawidd6/action-download-artifact@v2 + with: + path: artifacts + + - name: Package release assets + run: scripts/package-release-assets.sh + + - name: Create release + uses: softprops/action-gh-release@v1 + with: + draft: true + files: release/ouch-* diff --git a/.github/workflows/manual-release.yml b/.github/workflows/manual-release.yml new file mode 100644 index 0000000..b745f1c --- /dev/null +++ b/.github/workflows/manual-release.yml @@ -0,0 +1,33 @@ +name: manual-release + +on: + workflow_dispatch: + inputs: + run_id: + description: Run id of the action run to pull artifacts from + required: true + +jobs: + github-release: + name: github-release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Download artifacts + uses: dawidd6/action-download-artifact@v2 + with: + path: artifacts + workflow: build-and-test.yml + run_id: ${{ github.event.inputs.run_id }} + + - name: Package release assets + run: scripts/package-release-assets.sh + + - name: Create release + uses: softprops/action-gh-release@v1 + with: + draft: true + name: manual release ${{ github.event.inputs.run_id }} + files: release/ouch-* diff --git a/release-helper.sh b/release-helper.sh deleted file mode 100644 index 7f0ca59..0000000 --- a/release-helper.sh +++ /dev/null @@ -1,21 +0,0 @@ -#! /usr/bin/sh -# -# Small script to help decompressing files from the CI to make manual releases - -set -e - -ouch --version - -rm release -r || true - -ouch decompress ouch-x86_64-pc-windows-msvc.exe.zip --dir release -mv release/ouch.exe release/ouch-x86_64-pc-windows-msvc.exe - -ouch decompress ouch-x86_64-apple-darwin.zip --dir release -mv release/ouch release/ouch-x86_64-apple-darwin - -ouch decompress ouch-x86_64-unknown-linux-musl.zip --dir release -mv release/ouch release/ouch-x86_64-linux-musl - -dragon-drag-and-drop release/* - diff --git a/scripts/package-release-assets.sh b/scripts/package-release-assets.sh new file mode 100755 index 0000000..d9875ab --- /dev/null +++ b/scripts/package-release-assets.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -e + +mkdir release +cd artifacts + +for dir in ouch-*; do + cp -r artifacts "$dir/completions" + mkdir "$dir/man" + mv "$dir"/completions/*.1 "$dir/man" + cp ../{README.md,LICENSE,CHANGELOG.md} "$dir" + + if [[ "$dir" = *.exe ]]; then + target=${dir%.exe} + mv "$dir" "$target" + zip -r "../release/$target.zip" "$target" + else + chmod +x "$dir/ouch" + tar czf "../release/$dir.tar.gz" "$dir" + fi +done