move versioning logic into csproj & simplify build commands #931
Workflow file for this run
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: publish | |
on: | |
push: | |
paths: | |
- "Directory.Build.props" | |
- "Dockerfile*" | |
- "src/**" | |
- ".github/workflows/publish.yml" | |
branches: | |
- main | |
pull_request: | |
paths: | |
- "Directory.Build.props" | |
- "Dockerfile*" | |
- "src/**" | |
- ".github/workflows/publish.yml" | |
workflow_dispatch: | |
inputs: | |
version_number: | |
required: true | |
description: "The version number (dot-separated numbers only)" | |
prerelease: | |
description: "If true, the release will be set as a prerelease" | |
type: boolean | |
required: true | |
default: false | |
jobs: | |
create_release: | |
if: github.event_name == 'workflow_dispatch' && (github.ref == 'refs/heads/main' || github.event.inputs.prerelease == 'true') | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.create.outputs.version }} | |
release_id: ${{ steps.create.outputs.release_id }} | |
steps: | |
- name: Create release | |
id: create | |
env: | |
VERSION_NUMBER: ${{ github.event.inputs.version_number }} | |
PRERELEASE: ${{ github.event.inputs.prerelease }} | |
GH_TOKEN: ${{ github.token }} | |
shell: pwsh | |
run: | | |
if ( -Not ( $env:VERSION_NUMBER -match '^3\.[0-9]+\.[0-9]+$' ) ){ | |
Throw "Invalid version format" | |
} | |
$version = $env:VERSION_NUMBER | |
if ($env:PRERELEASE -eq 'true') { | |
$version = "${version}-preview-$(Get-Date -AsUTC -Format 'yyyyMMddHHmmss')" | |
$releaseUrl = gh release create "v${version}" --repo Brightspace/bmx --draft --prerelease --generate-notes --title "Release v${version}" --target $env:GITHUB_SHA | |
} else { | |
$releaseUrl = gh release create "v${version}" --repo Brightspace/bmx --draft --generate-notes --title "Release v${version}" --target $env:GITHUB_SHA | |
} | |
if ( $LASTEXITCODE -ne 0 ) { throw "Failed to create draft release" } | |
"version=$version" >> $env:GITHUB_OUTPUT | |
$releaseId = $releaseUrl -split '/' | Select-Object -Last 1 | |
"release_id=$releaseId" >> $env:GITHUB_OUTPUT | |
build: | |
needs: create_release | |
if: ${{ !failure() }} | |
strategy: | |
matrix: | |
include: | |
- machine: windows-latest | |
platform: win | |
file_name: bmx.exe | |
- machine: macos-latest | |
platform: osx | |
file_name: bmx | |
runs-on: ${{ matrix.machine }} | |
timeout-minutes: 10 | |
env: | |
PLATFORM: ${{ matrix.platform }} | |
steps: | |
- name: checkout | |
uses: Brightspace/third-party-actions@actions/checkout | |
- name: set up .NET | |
uses: Brightspace/third-party-actions@actions/setup-dotnet | |
with: | |
dotnet-version: 9.0.x | |
- name: publish | |
shell: pwsh | |
env: | |
Version: ${{ needs.create_release.outputs.version }} | |
working-directory: src/D2L.Bmx | |
run: | | |
dotnet publish -r $env:PLATFORM-x64 -o build/x64 | |
dotnet publish -r $env:PLATFORM-arm64 -o build/arm64 | |
- name: check size | |
shell: pwsh | |
working-directory: src/D2L.Bmx | |
run: | | |
Get-ChildItem build/x64 | |
Get-ChildItem build/arm64 | |
- name: upload build | |
if: github.event_name == 'workflow_dispatch' | |
shell: pwsh | |
env: | |
RELEASE_ID: ${{ needs.create_release.outputs.release_id }} | |
PLATFORM: ${{ matrix.platform }} | |
FILE_NAME: ${{ matrix.file_name }} | |
GH_TOKEN: ${{ github.token }} | |
working-directory: src/D2L.Bmx/build | |
run: | | |
if ($env:PLATFORM -eq 'win') { | |
Push-Location "x64" | |
Compress-Archive -Path "bmx.exe" -DestinationPath "bmx-win-x64.zip" | |
gh release upload "$env:RELEASE_ID" "bmx-win-x64.zip" | |
Pop-Location | |
Push-Location "arm64" | |
Compress-Archive -Path "bmx.exe" -DestinationPath "bmx-win-arm64.zip" | |
gh release upload "$env:RELEASE_ID" "bmx-win-arm64.zip" | |
Pop-Location | |
} elseif ($env:PLATFORM -eq 'osx') { | |
chmod +x "./x64/bmx" | |
chmod +x "./arm64/bmx" | |
Push-Location "x64" | |
tar -czvf "bmx-osx-x64.tar.gz" "bmx" | |
gh release upload "$env:RELEASE_ID" "bmx-osx-x64.tar.gz" | |
Pop-Location | |
Push-Location "arm64" | |
tar -czvf "bmx-osx-arm64.tar.gz" "bmx" | |
gh release upload "$env:RELEASE_ID" "bmx-osx-arm64.tar.gz" | |
Pop-Location | |
} | |
build_docker: | |
needs: create_release | |
if: ${{ !failure() }} | |
strategy: | |
matrix: | |
include: | |
- file: Dockerfile.al2 | |
platform: linux | |
architecture: x64 | |
- file: Dockerfile.alpine | |
platform: linux.alpine | |
architecture: x64 | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: checkout | |
uses: Brightspace/third-party-actions@actions/checkout | |
- name: setup docker buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: publish | |
shell: pwsh | |
env: | |
DOCKERFILE: ${{ matrix.file }} | |
Version: ${{ needs.create_release.outputs.version }} | |
run: | | |
docker buildx build ` | |
-f $env:DOCKERFILE ` | |
--build-arg version=$env:Version ` | |
-o build . | |
- name: check size | |
run: ls -l build | |
- name: upload build | |
if: github.event_name == 'workflow_dispatch' | |
shell: bash | |
env: | |
RELEASE_ID: ${{ needs.create_release.outputs.release_id }} | |
ARCHITECTURE: ${{ matrix.architecture }} | |
PLATFORM: ${{ matrix.platform }} | |
GH_TOKEN: ${{ github.token }} | |
working-directory: build | |
run: | | |
chmod +x "bmx" | |
tar -czvf "bmx-$PLATFORM-$ARCHITECTURE.tar.gz" "bmx" | |
gh release upload "$RELEASE_ID" "bmx-$PLATFORM-$ARCHITECTURE.tar.gz" | |
# We only auto publish prereleases and not real releases. The latter should stay as draft and only be published manually after review. | |
publish_prerelease: | |
needs: [create_release, build, build_docker] | |
if: github.event.inputs.prerelease == 'true' | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
env: | |
RELEASE_ID: ${{ needs.create_release.outputs.release_id }} | |
GH_TOKEN: ${{ github.token }} | |
steps: | |
- name: finalize release | |
run: | | |
gh release edit "$RELEASE_ID" --draft=false --repo Brightspace/bmx |