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: jobs:
build: build:
name: Build and Test name: Build and Test
runs-on: ${{ matrix.os }}
strategy: strategy:
fail-fast: false fail-fast: false
@ -22,45 +21,39 @@ jobs:
- target: x86_64-unknown-linux-gnu - target: x86_64-unknown-linux-gnu
os: ubuntu-latest os: ubuntu-latest
output: cargo-binstall output: cargo-binstall
archive: tgz
use-cross: false use-cross: false
test: true test: true
- target: x86_64-apple-darwin - target: x86_64-apple-darwin
os: macos-latest os: macos-latest
output: cargo-binstall output: cargo-binstall
archive: zip
use-cross: false use-cross: false
test: true test: true
- target: aarch64-apple-darwin - target: aarch64-apple-darwin
os: macos-latest os: macos-latest
output: cargo-binstall output: cargo-binstall
archive: zip
use-cross: false use-cross: false
test: false test: false
- target: x86_64-pc-windows-msvc - target: x86_64-pc-windows-msvc
os: windows-latest os: windows-latest
output: cargo-binstall.exe output: cargo-binstall.exe
archive: zip
use-cross: false use-cross: false
test: false test: false
- target: x86_64-unknown-linux-musl - target: x86_64-unknown-linux-musl
os: ubuntu-latest os: ubuntu-latest
output: cargo-binstall output: cargo-binstall
archive: tgz
use-cross: false use-cross: false
test: true test: true
- target: armv7-unknown-linux-musleabihf - target: armv7-unknown-linux-musleabihf
os: ubuntu-20.04 os: ubuntu-20.04
output: cargo-binstall output: cargo-binstall
archive: tgz
use-cross: true use-cross: true
test: false test: false
- target: aarch64-unknown-linux-musl - target: aarch64-unknown-linux-musl
os: ubuntu-latest os: ubuntu-latest
output: cargo-binstall output: cargo-binstall
archive: tgz
use-cross: true use-cross: true
test: false test: false
runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
@ -122,30 +115,74 @@ jobs:
./${{ matrix.output }} binstall --manifest-path . --no-confirm cargo-binstall ./${{ matrix.output }} binstall --manifest-path . --no-confirm cargo-binstall
cargo binstall --help cargo binstall --help
- name: Create archive (tgz, linux) - name: Upload output
if: ${{ matrix.os != 'macos-latest' && matrix.os != 'windows-latest' }} uses: actions/upload-artifact@v3
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
with: with:
name: cargo-binstall-${{ matrix.target }}.${{ matrix.archive }} retention-days: 1
path: cargo-binstall-${{ matrix.target }}.${{ matrix.archive }} name: "${{ matrix.target }}.${{ matrix.output }}"
path: "${{ matrix.output }}"
- name: Upload binary to release release:
if: ${{ startsWith(github.ref, 'refs/tags/v') }} name: Package and release
uses: svenstaro/upload-release-action@v2 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: with:
repo_token: ${{ secrets.GITHUB_TOKEN }} path: outputs/
file: cargo-binstall-${{ matrix.target }}.${{ matrix.archive }}
asset_name: cargo-binstall-${{ matrix.target }}.${{ matrix.archive }} - name: Create archives
tag: ${{ github.ref }} shell: bash
overwrite: true 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: ''

View file

@ -75,6 +75,9 @@ mimalloc = ["dep:mimalloc"]
[dev-dependencies] [dev-dependencies]
env_logger = "0.9.0" env_logger = "0.9.0"
[build-dependencies]
embed-resource = "1.6.1"
[profile.release] [profile.release]
opt-level = "z" opt-level = "z"
lto = true lto = true

View file

@ -1,5 +1,7 @@
// Fetch build target and define this for the compiler
fn main() { fn main() {
embed_resource::compile("manifest.rc");
// Fetch build target and define this for the compiler
println!( println!(
"cargo:rustc-env=TARGET={}", "cargo:rustc-env=TARGET={}",
std::env::var("TARGET").unwrap() std::env::var("TARGET").unwrap()

2
manifest.rc Normal file
View file

@ -0,0 +1,2 @@
#define RT_MANIFEST 24
1 RT_MANIFEST "windows.manifest"

16
release.toml Normal file
View file

@ -0,0 +1,16 @@
pre-release-commit-message = "release: v{{version}}"
tag-prefix = "cli-"
tag-message = "cargo-binstall {{version}}"
# We wait until the release CI is done before publishing,
# because publishing is irreversible, but a release can be
# reverted a lot more easily.
publish = false
[[pre-release-replacements]]
file = "windows.manifest"
search = "^ version=\"[\\d.]+[.]0\""
replace = " version=\"{{version}}.0\""
prerelease = false
max = 1

41
windows.manifest Normal file
View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
type="win32"
name="Binstall.Cli.binstall"
version="0.10.0.0"
/>
<trustInfo>
<security>
<!--
UAC settings:
- app should run at same integrity level as calling process
- app does not need to manipulate windows belonging to
higher-integrity-level processes
-->
<requestedPrivileges>
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- Windows 10, 11 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
</application>
</compatibility>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings xmlns:ws="http://schemas.microsoft.com/SMI/2020/WindowsSettings">
<ws:longPathAware xmlns:ws="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</ws:longPathAware>
<ws:activeCodePage xmlns:ws="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</ws:activeCodePage>
<ws:heapType xmlns:ws="http://schemas.microsoft.com/SMI/2020/WindowsSettings">SegmentHeap</ws:heapType>
</windowsSettings>
</application>
</assembly>