Skip to content

Build & Release

Build & Release #10

name: Build & Release
on:
push:
tags:
- '*.*.*'
workflow_dispatch:
jobs:
# lint:
# uses: ./.github/workflows/lint.yaml
# coverage:
# uses: ./.github/workflows/coverage.yaml
# benchmark:
# uses: ./.github/workflows/benchmark.yaml
build-and-test:
name: '${{ matrix.target }}'
# needs:
# - benchmark
# - coverage
# - lint
runs-on: ${{ matrix.runs-on }}
outputs:
CALCULATED_VERSION: ${{ steps.version.outputs.CALCULATED_VERSION }}
IS_PRE_RELEASE: ${{ steps.version.outputs.IS_PRE_RELEASE }}
PREV_RELEASE_VERSION: ${{ steps.version.outputs.PREV_RELEASE_VERSION }}
strategy:
matrix:
include:
- runs-on: ubuntu-latest
target: x86_64-unknown-linux-musl
- runs-on: macos-latest
target: x86_64-apple-darwin
- runs-on: windows-latest
target: x86_64-pc-windows-msvc
env:
RUST_LOG: trace
steps:
- uses: actions/checkout@v4
with:
# We set a the fetch depth so we expect BuildIt to be able to find the previous version tag.
# A value of 0 will fetch all commits, but that is overkill.
fetch-depth: 1000
# We also need to fetch tags as by default no tags are fetched if fetch-depth above is greater than 0.
# Tags are used to calculate the next version number.
- name: Fetch tags
run: git fetch --tags origin
- uses: ./.github/actions/detect-and-install-rust-toolchain
- uses: ./.github/actions/run-all-tests
- uses: ./.github/actions/install-buildit
- name: Set the build version
id: version
run: buildit version
- name: Build binaries for packaging
run: cargo build --release --all-features
- uses: ./.github/actions/package-linux
if: ${{ matrix.runs-on == 'ubuntu-latest' }}
with:
target: ${{ matrix.target }}
- uses: ./.github/actions/package-macos
if: ${{ matrix.runs-on == 'macos-latest' }}
with:
target: ${{ matrix.target }}
- uses: ./.github/actions/package-windows
if: ${{ matrix.runs-on == 'windows-latest' }}
with:
target: ${{ matrix.target }}
- name: Upload distribution artifacts
uses: actions/upload-artifact@v3
with:
name: dist-${{ matrix.target }}
path: ./artifacts/dist
create-release:
name: Create release
needs: build-and-test
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
CALCULATED_VERSION: ${{ needs.build-and-test.outputs.CALCULATED_VERSION }}
IS_PRE_RELEASE: ${{ needs.build-and-test.outputs.IS_PRE_RELEASE }}
PREV_RELEASE_VERSION: ${{ needs.build-and-test.outputs.PREV_RELEASE_VERSION }}
permissions:
contents: write # Allow release creation
steps:
- uses: actions/checkout@v4
with:
# We set a the fetch depth so we expect minver_rs to be able to find the last version tag.
# A value of 0 will fetch all commits, but that is overkill.
fetch-depth: 1000
- name: Download all workflow run artifacts
uses: actions/download-artifact@v3
- name: Create release
# Temporarily disable release creation to test pages task below
# TODO: Remove this when done testing
if: ${{ false }}
shell: pwsh
run: |
$isPreReleaseVar = '${{ env.IS_PRE_RELEASE }}'
$prevReleaseVersion = '${{ env.PREV_RELEASE_VERSION }}'
$calculatedVersion = '${{ env.CALCULATED_VERSION }}'
Write-Host "IS_PRE_RELEASE = $isPreReleaseVar"
Write-Host "PREV_RELEASE_VERSION = $prevReleaseVersion"
Write-Host "CALCULATED_VERSION = $calculatedVersion"
$isPreRelease = $true
$preReleaseParam = '--prerelease'
if ($isPreReleaseVar -eq 'false') {
Write-Host 'This is a release'
$isPreRelease = $false
$preReleaseParam = $null
} else {
Write-Host 'This is a pre-release'
}
$hasPrevReleaseVersion = -not [string]::IsNullOrWhiteSpace($prevReleaseVersion)
if ($hasPrevReleaseVersion) {
Write-Host "Will create release $calculatedVersion from tag $prevReleaseVersion to tag $calculatedVersion"
gh release create $calculatedVersion $preReleaseParam --generate-notes --latest --notes-start-tag $prevReleaseVersion --title $calculatedVersion
} else {
Write-Host "Will create first release $calculatedVersion"
gh release create $calculatedVersion $preReleaseParam --notes 'First release' --title $calculatedVersion
}
$targets = @('x86_64-unknown-linux-musl', 'x86_64-apple-darwin', 'x86_64-pc-windows-msvc')
foreach ($target in $targets) {
$targetArtifactsDir = "./dist-$target"
if (Test-Path $targetArtifactsDir) {
gh release upload $calculatedVersion $targetArtifactsDir/*
}
}
publish-scoop-manifest:
if: github.ref == 'refs/heads/main'
needs: build-and-test
runs-on: ubuntu-latest
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
# Deploy to the github-pages environment
environment:
name: github-pages
url: https://emilevr.github.io/space
steps:
- name: Fix permissions
run: |
chmod -c -R +rX "./artifacts/dist/pages/" | while read line; do
echo "::warning title=Invalid file permissions automatically fixed::$line"
done
- name: Compress pages
run: |
tar -C ./artifacts/dist/pages/ -czf github-pages
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v2
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2