Releng improvements (#224)

This commit is contained in:
Félix Saparelli 2022-07-24 00:39:54 +12:00 committed by GitHub
parent 1768392413
commit 3889d122a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 240 additions and 33 deletions

View file

@ -13,7 +13,6 @@ env:
jobs:
build:
name: Build and Test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
@ -22,45 +21,39 @@ jobs:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
output: cargo-binstall
archive: tgz
use-cross: false
test: true
- target: x86_64-apple-darwin
os: macos-latest
output: cargo-binstall
archive: zip
use-cross: false
test: true
- target: aarch64-apple-darwin
os: macos-latest
output: cargo-binstall
archive: zip
use-cross: false
test: false
- target: x86_64-pc-windows-msvc
os: windows-latest
output: cargo-binstall.exe
archive: zip
use-cross: false
test: false
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
output: cargo-binstall
archive: tgz
use-cross: false
test: true
- target: armv7-unknown-linux-musleabihf
os: ubuntu-20.04
output: cargo-binstall
archive: tgz
use-cross: true
test: false
- target: aarch64-unknown-linux-musl
os: ubuntu-latest
output: cargo-binstall
archive: tgz
use-cross: true
test: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
@ -122,30 +115,74 @@ jobs:
./${{ matrix.output }} binstall --manifest-path . --no-confirm cargo-binstall
cargo binstall --help
- name: Create archive (tgz, linux)
if: ${{ matrix.os != 'macos-latest' && matrix.os != 'windows-latest' }}
run: tar -czvf cargo-binstall-${{ matrix.target }}.tgz ${{ matrix.output }}
- name: Create archive (zip, windows)
if: ${{ matrix.os == 'windows-latest' }}
run: tar.exe -a -c -f cargo-binstall-${{ matrix.target }}.zip ${{ matrix.output }}
- name: Create archive (zip, macos)
if: ${{ matrix.os == 'macos-latest' }}
run: zip cargo-binstall-${{ matrix.target }}.zip ${{ matrix.output }}
- name: Upload artifacts
uses: actions/upload-artifact@v1
- name: Upload output
uses: actions/upload-artifact@v3
with:
name: cargo-binstall-${{ matrix.target }}.${{ matrix.archive }}
path: cargo-binstall-${{ matrix.target }}.${{ matrix.archive }}
retention-days: 1
name: "${{ matrix.target }}.${{ matrix.output }}"
path: "${{ matrix.output }}"
- name: Upload binary to release
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
uses: svenstaro/upload-release-action@v2
release:
name: Package and release
needs: build
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Get outputs
uses: actions/download-artifact@v3
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: cargo-binstall-${{ matrix.target }}.${{ matrix.archive }}
asset_name: cargo-binstall-${{ matrix.target }}.${{ matrix.archive }}
tag: ${{ github.ref }}
overwrite: true
path: outputs/
- name: Create archives
shell: bash
run: |
set -euxo pipefail
for o in outputs/*; do
pushd "$o"
cp ../../LICENSE.txt ../../README.md .
target=$(basename "$o" | cut -d. -f1)
if grep -qE '(apple|windows)' <<< "$target"; then
zip "../cargo-binstall-${target}.zip" *
else
tar cvf "../cargo-binstall-${target}.tgz" *
fi
popd
done
- name: Extract release notes
id: notes
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPO: ${{ github.repository }}
release_commit: ${{ github.event.head_commit.message }}
run: |
set -euxo pipefail
release_pr=$(head -n1 <<< "${release_commit:-}" | jq -Rr 'split("[()]"; "")[1] // ""')
if [[ -z "$release_pr" ]]; then
echo "::set-output name=notes_json::null"
exit
fi
gh \
pr --repo "$GITHUB_REPO" \
view "$release_pr" \
--json body \
--jq '"::set-output name=notes_json::\((.body | split("### Release notes")[1] // "") | tojson)"'
- name: Publish release
uses: softprops/action-gh-release@50195ba7f6f93d1ac97ba8332a178e008ad176aa
with:
tag_name: ${{ github.ref }}
name: ${{ github.ref }}
body: ${{ fromJSON(steps.notes.outputs.notes_json) }}
append_body: true
files: |
outputs/cargo-binstall-*.zip
outputs/cargo-binstall-*.tgz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

74
.github/workflows/release-pr.yml vendored Normal file
View file

@ -0,0 +1,74 @@
name: Open a release PR
on:
workflow_dispatch:
inputs:
version:
description: Version to release
required: true
type: string
jobs:
make-release-pr:
runs-on: ubuntu-latest
steps:
- name: Install cargo-release
uses: taiki-e/install-action@v1
with:
tool: cargo-release
- uses: actions/checkout@v2
with:
ref: main
- name: Extract info
run: |
set -euxo pipefail
branch_name="release-${{ inputs.version }}"
echo "branch_name=${branch_name}" >> $GITHUB_ENV
- name: Make release branch
run: git switch -c "${{ env.branch_name }}"
- name: Do release
run: |
set -euxo pipefail
git config user.name github-actions
git config user.email github-actions@github.com
cargo release \
--execute \
--no-push \
--no-tag \
--no-publish \
--no-confirm \
--verbose \
--config release.toml \
--allow-branch "${{ env.branch_name }}" \
--dependent-version upgrade \
"${{ inputs.version }}"
- name: Push new branch
run: |
set -euxo pipefail
git push origin "${{ env.branch_name }}"
- name: Create PR
run: |
set -euxo pipefail
nl=$'\n'
br=$'\n\n'
fence=$'```\n'
ecnef=$'\n```'
title="release: v${{ inputs.version }}"
body_intro="This is a release PR for version **${{ inputs.version }}**."
body_merge="**Use squash merge.** Upon merging, this will automatically build the CLI and create a GitHub release. You still need to manually publish the cargo crate."
body_pub="${fence}$ cd ${{ env.crate_path }}${nl}$ cargo publish${ecnef}"
body_notes="---${br}_Edit release notes into the section below:_${br}<!-- do not change or remove this heading -->${nl}### Release notes"
body="${body_intro}${br}${body_merge}${br}${body_pub}${br}${body_notes}${br}"
gh pr create --title "$title" --body "$body" --base main --head "${{ env.branch_name }}" --label "release"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

32
.github/workflows/release-tag.yml vendored Normal file
View file

@ -0,0 +1,32 @@
name: Tag a release
on:
push:
branches:
- main
tags-ignore:
- "*"
jobs:
make-tag:
runs-on: ubuntu-latest
# the commit message will look like: `release: v{version} (#{pr-number})`
if: "startsWith(github.event.head_commit.message, 'release: v')"
steps:
- name: Extract tag from commit message
env:
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
run: |
set -euxo pipefail
message="$(head -n1 <<< "$COMMIT_MESSAGE")"
version="$(cut -d ' ' -f 2 <<< "${message}")"
echo "CUSTOM_TAG=${version}" >> $GITHUB_ENV
- uses: actions/checkout@v2
- name: Push release tag
id: tag_version
uses: mathieudutour/github-tag-action@v6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
custom_tag: ${{ env.CUSTOM_TAG }}
tag_prefix: ''