release #207
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: release | |
on: | |
# schedule: | |
# - cron: "5 5 * * *" | |
workflow_dispatch: | |
inputs: | |
tag_name: | |
description: "Tag name for release" | |
required: false | |
default: nightly | |
push: | |
tags: | |
- "[0-9]+.[0-9]+.[0-9]+" | |
env: | |
CARGO_TERM_COLOR: always | |
USE_CROSS: true | |
FETCH_DEPTH: 0 | |
RELEASE_NAME: "stow-cm" | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
create-release: | |
name: create-release | |
runs-on: ubuntu-latest | |
outputs: | |
release_version: ${{ env.release_version }} | |
upload_url: ${{ steps.release.outputs.upload_url }} | |
steps: | |
- if: github.event_name == 'workflow_dispatch' | |
run: echo "release_version=${{ inputs.tag_name }}" >> $GITHUB_ENV | |
- if: github.event_name == 'schedule' | |
run: echo "release_version=nightly" >> $GITHUB_ENV | |
- if: github.event_name == 'push' | |
run: | |
echo "release_version=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | |
# echo "::set-output name=release_version::${{ env.release_version }}" | |
- id: release | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
let release_label | |
if ("nightly" === "${{ env.release_version }}") { | |
release_label = "nightly"; | |
} else { | |
release_label = "stable"; | |
} | |
try { | |
const { data: { id:release_id } } = await github.rest.repos.getReleaseByTag({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag: release_label, | |
}); | |
if ( release_id ) { | |
await github.rest.repos.deleteRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
release_id, | |
}); | |
} | |
await github.rest.git.deleteRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: `tags/${release_label}`, | |
}); | |
} catch (e) { | |
console.error(e) | |
} | |
let is_nightly = "nightly" === release_label | |
let upload_url = []; | |
// create tag release | |
let target_commitish; | |
if (!is_nightly) { | |
const { data: { upload_url: tag_update_url } } = await github.rest.repos.createRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag_name: "${{ env.release_version }}", | |
name: "Release ${{ env.release_version }}", | |
}); | |
upload_url.push(tag_update_url); | |
const { data: { object: { sha: tag_sha } } } = await github.rest.git.getRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: "tags/${{ env.release_version }}", | |
}); | |
const { data: { object: { sha: commit_sha } } } = await github.rest.git.getTag({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag_sha: tag_sha, | |
}); | |
target_commitish = commit_sha; | |
} | |
// create label release | |
let opts = { | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag_name: release_label, | |
name: `Release ${ release_label }`, | |
prerelease: is_nightly, | |
draft: false, | |
} | |
if (target_commitish) { | |
opts.target_commitish = target_commitish | |
} | |
console.log("opts:", JSON.stringify(opts)) | |
const { data: { upload_url: label_update_url } } = await github.rest.repos.createRelease(opts); | |
upload_url.push(label_update_url); | |
core.setOutput("upload_url", JSON.stringify(upload_url)); | |
update-release: | |
name: update-release | |
needs: [create-release] | |
runs-on: ${{ matrix.build.os }} | |
continue-on-error: true | |
strategy: | |
fail-fast: false | |
matrix: | |
# build: [linux, linux-arm, macos, win-msvc, win-gnu, win32-msvc] | |
build: [ | |
{ | |
plat: linux, | |
os: ubuntu-latest, | |
rust: stable, | |
target: x86_64-unknown-linux-musl, | |
}, | |
{ | |
plat: macos, | |
os: macos-latest, | |
rust: stable, | |
target: x86_64-apple-darwin, | |
}, | |
# { | |
# plat: linux-arm, | |
# os: ubuntu-latest, | |
# rust: stable, | |
# target: arm-unknown-linux-gnueabihf | |
# }, | |
# { | |
# plat: win-msvc, | |
# os: windows-latest, | |
# rust: stable, | |
# target: x86_64-pc-windows-msvc | |
# }, | |
# { | |
# plat: win-gnu, | |
# os: windows-latest, | |
# rust: stable-x86_64-gnu, | |
# target: x86_64-pc-windows-gnu | |
# }, | |
# { | |
# plat: win32-msvc, | |
# os: windows-latest, | |
# rust: stable, | |
# target: i686-pc-windows-msvc | |
# }, | |
] | |
upload_url: ${{ fromJSON(needs.create-release.outputs.upload_url) }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: ${{ env.FETCH_DEPTH }} | |
- uses: actions-rs/toolchain@v1 | |
with: | |
override: true | |
profile: minimal | |
toolchain: ${{ matrix.build.rust }} | |
- uses: Swatinem/rust-cache@v2 | |
- name: build release binary | |
uses: actions-rs/cargo@v1 | |
with: | |
command: build | |
args: --release --target=${{ matrix.build.target }} | |
use-cross: ${{ env.USE_CROSS }} | |
- name: Strip release binary (linux and macos) | |
if: matrix.build.plat == 'linux' || matrix.build.plat == 'macos' | |
run: strip "target/${{ matrix.build.target }}/release/${{ env.RELEASE_NAME }}" | |
- name: Strip release binary (arm) | |
if: matrix.build.plat == 'linux-arm' | |
run: | | |
docker run --rm -v \ | |
"$PWD/target:/target:Z" \ | |
rustembedded/cross:arm-unknown-linux-gnueabihf \ | |
arm-linux-gnueabihf-strip \ | |
/target/arm-unknown-linux-gnueabihf/release/${{ env.RELEASE_NAME }} | |
- name: Build archive | |
shell: bash | |
run: | | |
staging="${{ env.RELEASE_NAME }}-${{ matrix.build.target }}" | |
mkdir -p "$staging" | |
cp {README.md,LICENSE} "$staging/" | |
if [ "${{ matrix.build.os }}" = "windows-latest" ]; then | |
cp "target/${{ matrix.build.target }}/release/${{ env.RELEASE_NAME }}.exe" "$staging/" | |
7z a "$staging.zip" "$staging" | |
echo "ASSET=$staging.zip" >> $GITHUB_ENV | |
sha256sum "$staging.zip" > "$staging.zip.sha256sum" | |
echo "ASSET_SHA256SUM=$staging.zip.sha256sum" >> $GITHUB_ENV | |
else | |
cp "target/${{ matrix.build.target }}/release/${{ env.RELEASE_NAME }}" "$staging/" | |
tar czf "$staging.tar.gz" "$staging" | |
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV | |
shasum -a 256 "$staging.tar.gz" > "$staging.tar.gz.sha256sum" | |
echo "ASSET_SHA256SUM=$staging.tar.gz.sha256sum" >> $GITHUB_ENV | |
fi | |
- name: Upload release archive | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ matrix.upload_url }} | |
asset_path: ${{ env.ASSET }} | |
asset_name: ${{ env.ASSET }} | |
asset_content_type: application/octet-stream | |
- name: Upload release archive sha256sum | |
if: env.ASSET_SHA256SUM != null | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ matrix.upload_url }} | |
asset_path: ${{ env.ASSET }}.sha256sum | |
asset_name: ${{ env.ASSET }}.sha256sum | |
asset_content_type: application/octet-stream |