From 35891f8f4920806973e354727df1c977251a6202 Mon Sep 17 00:00:00 2001 From: Noah Hellman Date: Fri, 12 Jan 2024 22:47:51 +0100 Subject: [PATCH] add release ci action --- .github/workflows/release.yml | 104 ++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fb43acd --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,104 @@ +name: release + +on: + push: + tags: ["[0-9]+.[0-9]+.[0-9]+*"] + +permissions: + contents: write + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + create: + name: create release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.ref_name }} + - name: verify version matches + shell: bash + run: grep -q 'version = "${{ github.ref_name }}"' Cargo.toml || { echo version mismatch >&2 && exit 1; } + - name: create release + run: gh release create ${{ github.ref_name }} --draft --verify-tag --title "Release ${{ github.ref_name }}" + + build: + name: build + needs: ['create'] + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - os: ubuntu-latest + target: i686-unknown-linux-musl + - os: macos-latest + target: x86_64-apple-darwin + - os: macos-latest + target: aarch64-apple-darwin + - os: windows-latest + target: x86_64-pc-windows-msvc + - os: windows-latest + target: i686-pc-windows-msvc + + steps: + - name: checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.ref_name }} + + - name: install rust + shell: bash + run: | + rustup update stable + rustup target add ${{ matrix.target }} + + - name: build + shell: bash + run: | + if [ -n "${{ matrix.linker }}" ]; then + export RUSTFLAGS="-Clinker=${{ matrix.linker }}" + fi + cargo build --verbose --release --target ${{ matrix.target }} + find . + bin="target/${{ matrix.target }}/release/jotdown" + [ "${{ matrix.os }}" = "windows-latest" ] && bin="$bin.exe" + echo "BIN=$bin" >> $GITHUB_ENV + + - name: strip + if: ${{ startsWith(matrix.os, 'ubuntu') }} + run: strip $BIN + + - name: set archive name + shell: bash + run: echo "ARCHIVE=jotdown-${{ github.ref_name }}-${{ matrix.target }}" >> $GITHUB_ENV + + - name: init archive dir + shell: bash + run: | + mkdir "$ARCHIVE"/ + cp "$BIN" "$ARCHIVE"/ + cp {COPYING,CHANGELOG.md,README.md} "$ARCHIVE"/ + + - name: archive (win) + if: ${{ startsWith(matrix.os, 'windows') }} + shell: bash + run: | + 7z a "$ARCHIVE.zip" "$ARCHIVE" + echo "ASSET=$ARCHIVE.zip" >> $GITHUB_ENV + + - name: archive (unix) + if: ${{ ! startsWith(matrix.os, 'windows') }} + shell: bash + run: | + tar czf "$ARCHIVE.tar.gz" "$ARCHIVE" + echo "ASSET=$ARCHIVE.tar.gz" >> $GITHUB_ENV + + - name: Upload release archive + shell: bash + run: | + gh release upload ${{ github.ref_name }} ${{ env.ASSET }}