publish #644
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: | |
release_tag: | |
required: true | |
description: "Tag for the new release" | |
prerelease: | |
description: "If true, the release will be set as a prerelease and not impact the latest tag" | |
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: | |
release_id: ${{ steps.create.outputs.release_id }} | |
steps: | |
- name: Create release | |
id: create | |
env: | |
RELEASE_TAG: ${{ github.event.inputs.release_tag }} | |
PRERELEASE: ${{ github.event.inputs.prerelease }} | |
GH_TOKEN: ${{ github.token }} | |
shell: pwsh | |
run: | | |
if ( -Not ( $env:RELEASE_TAG -match '^v3\.[0-9]+\.[0-9]+(-preview)*' ) ){ | |
Throw "Tag name format incorrect" | |
} | |
if ($env:PRERELEASE -eq 'true') { | |
$releaseUrl = gh release create "$env:RELEASE_TAG" --repo Brightspace/bmx --draft --prerelease --generate-notes --title "Release $env:RELEASE_TAG" | |
} else { | |
$releaseUrl = gh release create "$env:RELEASE_TAG" --repo Brightspace/bmx --draft --generate-notes --title "Release $env:RELEASE_TAG" | |
} | |
if ( $LASTEXITCODE -ne 0 ) { throw "Failed to create draft release" } | |
$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: 8.0.x | |
- name: publish | |
shell: pwsh | |
env: | |
RELEASE_TAG: ${{ github.event.inputs.release_tag }} | |
working-directory: src/D2L.Bmx | |
run: | | |
$version = "$env:RELEASE_TAG" | |
if ( -not $version ){ | |
$version = "v3.0.0" | |
} | |
$versionWithoutv = "$version".TrimStart("v") | |
dotnet publish ` | |
/p:Version="$versionWithoutv" ` | |
/p:InformationalVersion="$version" ` | |
/p:IncludeSourceRevisionInInformationalVersion=false ` | |
-r $env:PLATFORM-x64 ` | |
-o build | |
- name: check size | |
shell: pwsh | |
working-directory: src/D2L.Bmx | |
run: Get-ChildItem build | |
- 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') { | |
Compress-Archive -Path "bmx.exe" -DestinationPath "bmx-win-x64.zip" | |
gh release upload "$env:RELEASE_ID" "bmx-win-x64.zip" | |
} elseif ($env:PLATFORM -eq 'osx') { | |
chmod +x "bmx" | |
tar -czvf "bmx-osx-x64.tar.gz" "bmx" | |
gh release upload "$env:RELEASE_ID" "bmx-osx-x64.tar.gz" | |
} | |
build_docker: | |
needs: create_release | |
if: ${{ !failure() }} | |
strategy: | |
matrix: | |
include: | |
- file: Dockerfile.al2 | |
platform: linux | |
- file: Dockerfile.alpine | |
platform: linux.alpine | |
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 }} | |
RELEASE_TAG: ${{ github.event.inputs.release_tag }} | |
run: | | |
$version = "$env:RELEASE_TAG" | |
if ( -not $version ){ | |
$version = "v3.0.0" | |
} | |
$versionWithoutv = "$version".TrimStart("v") | |
docker buildx build ` | |
-f $env:DOCKERFILE ` | |
--build-arg version=$versionWithoutv ` | |
--build-arg information_version=$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 }} | |
PLATFORM: ${{ matrix.platform }} | |
GH_TOKEN: ${{ github.token }} | |
working-directory: build | |
run: | | |
chmod +x "bmx" | |
tar -czvf "bmx-$PLATFORM-x64.tar.gz" "bmx" | |
gh release upload "$RELEASE_ID" "bmx-$PLATFORM-x64.tar.gz" | |
publish_release: | |
needs: [create_release, build, build_docker] | |
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 |