Skip to content

Build & Release

Build & Release #26

name: "Build & Release"
permissions:
# To upload files to GitHub Releases
contents: write
on:
workflow_dispatch:
inputs:
version:
type: string
description: "Version: (e.g. -> v3.1.4-alpha+159)"
release_type:
type: choice
default: none
options:
- none
- patch
- minor
- major
publish:
type: boolean
overwrite_tag:
type: boolean
workflow_call:
inputs:
version:
type: string
description: "Version: (e.g. -> v3.1.4-alpha+159)"
release_type:
type: string
publish:
type: boolean
overwrite_tag:
type: boolean
jobs:
validate-input:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate input
id: regex-match
run: |
text="${INPUT_VERSION}";
regex="^v([0-9]+)\.([0-9]+)\.([0-9]+)-?([[:alnum:]]*)\+?([0-9]*)$";
# Perform the regex match
if grep -qE "$regex" <<< "$text"; then
echo "match=true" >> "$GITHUB_OUTPUT";
else
echo "match=false" >> "$GITHUB_OUTPUT";
fi
- name: Fail if don't match regex
if: ${{ inputs.version && steps.regex-match.outputs.match == 'false' }}
run: |
echo "${{inputs.version}} doesn't match regex. Use a version similar to v3.1.4-alpha+159"
exit 1;
get-version:
needs: validate-input
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v4
- name: Install jql
if: ${{ !inputs.version }}
uses: taiki-e/install-action@v2
with:
tool: jql
- name: Install cargo-bump
if: ${{ !inputs.version }}
uses: taiki-e/install-action@v2
with:
tool: cargo-bump
- name: Versions using None
id: none_version
if: ${{ !inputs.version && inputs.release_type == 'none' }}
run: |
version=$(cargo metadata --format-version=1 --no-deps | jql '"packages"|>"version"<|[0]' --raw-string);
echo $version;
echo "crate_version=$version" >> "$GITHUB_OUTPUT";
normal_version=v$version
echo $normal_version;
echo "tag_version=$normal_version" >> "$GITHUB_OUTPUT";
- name: Versions using release_type
id: new_version
if: ${{ !inputs.version && inputs.release_type != 'none' }}
run: |
cargo bump ${{ inputs.release_type }};
version=$(cargo metadata --format-version=1 --no-deps | jql '"packages"|>"version"<|[0]' --raw-string);
echo $version;
echo "crate_version=$version" >> "$GITHUB_OUTPUT";
normal_version=v$version
echo $normal_version;
echo "tag_version=$normal_version" >> "$GITHUB_OUTPUT";
- name: Versions using tag
id: full_version
if: inputs.version
run: |
tag=${{inputs.version}};
echo $tag;
echo "crate_version=${tag##v} >> GITHUB_OUTPUT";
echo ${tag##v};
outputs:
new_tag_version: ${{ inputs.version || steps.new_version.outputs.tag_version || steps.none_version.outputs.tag_version }}
new_crate_version: ${{ steps.full_version.outputs.crate_version || steps.new_version.outputs.crate_version || steps.none_version.outputs.crate_version }}
check-crate-type:
uses: ./.github/workflows/crate_type.yaml
run-ci:
needs: validate-input
uses: ./.github/workflows/ci.yaml
add-notice:
needs: [get-version, run-ci]
uses: ./.github/workflows/add_notice.yaml
with:
commit_message: ${{ needs.get-version.outputs.new_crate_version }}
cargo-semver-checks:
needs: [get-version, run-ci]
uses: ./.github/workflows/cargo_semver_checks.yaml
with:
bump-version: ${{ needs.get-version.outputs.new_crate_version }}
bump-version:
needs: [get-version, cargo-semver-checks]
uses: ./.github/workflows/bump_version.yaml
with:
crate-version: ${{ needs.get-version.outputs.new_crate_version }}
update-attributions:
needs: [get-version, bump-version]
uses: ./.github/workflows/cargo_attribution.yaml
with:
commit_message: ${{ needs.get-version.outputs.new_crate_version }}
create-tag:
needs: [get-version, update-attributions]
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v4
- run: git pull
- uses: mukunku/[email protected]
if: ${{ inputs.overwrite_tag }}
id: check-tag-overwrite
with:
tag: ${{ needs.get-version.outputs.new_tag_version }}
- name: Delete tag
if: ${{ steps.check-tag-overwrite.outputs.exists == 'true' }}
run: |
git config user.name github-actions
git config user.email [email protected]
git fetch --tags
git tag -d ${{ needs.get-version.outputs.new_tag_version }}
git push -d origin ${{ needs.get-version.outputs.new_tag_version }}
- uses: mukunku/[email protected]
id: check-tag
with:
tag: ${{ needs.get-version.outputs.new_tag_version}}
- name: Create tag
if: steps.check-tag.outputs.exists == 'false'
run: |
git config user.name github-actions
git config user.email [email protected]
git tag ${{ needs.get-version.outputs.new_tag_version}}
git push origin ${{ needs.get-version.outputs.new_tag_version}}
create-release:
needs: [get-version, create-tag]
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
uses: actions/checkout@v4
- uses: taiki-e/create-gh-release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
changelog: CHANGELOG.md
allow-missing-changelog: true
ref: refs/tags/${{ needs.get-version.outputs.new_tag_version }}
build-and-release:
needs: [get-version, create-release, check-crate-type]
if: ${{ needs.check-crate-type.outputs.is_bin == 'true' }}
name: ${{ matrix.target }} (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- {os: ubuntu-latest, target: x86_64-unknown-linux-gnu, cross: false}
- {os: ubuntu-latest, target: x86_64-unknown-linux-musl, cross: true}
- {os: ubuntu-latest, target: aarch64-unknown-linux-gnu, cross: true}
- {os: ubuntu-latest, target: aarch64-unknown-linux-musl, cross: true}
- {os: ubuntu-latest, target: riscv64gc-unknown-linux-gnu, cross: true}
- {os: windows-latest, target: x86_64-pc-windows-msvc, cross: false}
- {os: windows-latest, target: aarch64-pc-windows-msvc, cross: false}
- {os: macos-latest, target: x86_64-apple-darwin, cross: false}
- {os: macos-latest, target: aarch64-apple-darwin, cross: false}
steps:
- name: Fetch Repository
uses: actions/checkout@v4
with:
ref: ${{ needs.get-version.outputs.new_tag_version }}
- name: Install stable toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
target: ${{ matrix.target }}
- name: Install cross-compilation tools
if: ${{ matrix.cross }} == 'true'
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: ${{ matrix.target }}
- uses: taiki-e/upload-rust-binary-action@v1
with:
bin: ${{ github.event.repository.name }}
target: ${{ matrix.target }}
include: attribution
archive: $bin-$tag-$target
token: ${{ secrets.GITHUB_TOKEN }}
ref: refs/tags/${{ needs.get-version.outputs.new_tag_version }}
checksum: sha256
publish-crate:
needs: [create-tag]
if: ${{ inputs.publish }}
uses: ./.github/workflows/publish.yaml
secrets: inherit