Skip to content

Check for elevated permissions with automatic login #872

Check for elevated permissions with automatic login

Check for elevated permissions with automatic login #872

Workflow file for this run

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" --target $env:GITHUB_SHA
} else {
$releaseUrl = gh release create "$env:RELEASE_TAG" --repo Brightspace/bmx --draft --generate-notes --title "Release $env:RELEASE_TAG" --target $env:GITHUB_SHA
}
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: 9.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/x64
dotnet publish `
/p:Version="$versionWithoutv" `
/p:InformationalVersion="$version" `
/p:IncludeSourceRevisionInInformationalVersion=false `
-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"
Pop-Location
Push-Location "arm64"
Compress-Archive -Path "bmx.exe" -DestinationPath "bmx-win-arm64.zip"
Pop-Location
gh release upload "$env:RELEASE_ID" "bmx-win-x64.zip"
gh release upload "$env:RELEASE_ID" "bmx-win-arm64.zip"
} elseif ($env:PLATFORM -eq 'osx') {
chmod +x "./x64/bmx"
chmod +x "./arm64/bmx"
Push-Location "x64"
tar -czvf "bmx-osx-x64.tar.gz" "bmx"
Pop-Location
Push-Location "arm64"
tar -czvf "bmx-osx-arm64.tar.gz" "bmx"
Pop-Location
gh release upload "$env:RELEASE_ID" "bmx-osx-x64.tar.gz"
gh release upload "$env:RELEASE_ID" "bmx-osx-arm64.tar.gz"
}
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 }}
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 }}
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"
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