From 159e1780b65d4a3c39adc1b82bc331757dfaf3e3 Mon Sep 17 00:00:00 2001 From: Chenfeng Bao Date: Fri, 27 Dec 2024 12:23:58 -0800 Subject: [PATCH] move versioning logic into csproj & simplify build commands (#498) --- .github/workflows/publish.yml | 44 +++++++++-------------------------- Dockerfile.al2 | 7 ++---- Dockerfile.alpine | 7 ++---- src/D2L.Bmx/D2L.Bmx.csproj | 9 +++++++ 4 files changed, 24 insertions(+), 43 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f02cce16..f3fdb92c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -31,7 +31,7 @@ jobs: if: github.event_name == 'workflow_dispatch' && (github.ref == 'refs/heads/main' || github.event.inputs.prerelease == 'true') runs-on: ubuntu-latest outputs: - release_tag: ${{ steps.create.outputs.release_tag }} + version: ${{ steps.create.outputs.version }} release_id: ${{ steps.create.outputs.release_id }} steps: - name: Create release @@ -45,16 +45,16 @@ jobs: if ( -Not ( $env:VERSION_NUMBER -match '^3\.[0-9]+\.[0-9]+$' ) ){ Throw "Invalid version format" } - $releaseTag = "v$($env:VERSION_NUMBER)" + $version = $env:VERSION_NUMBER if ($env:PRERELEASE -eq 'true') { - $releaseTag = "${releaseTag}-preview-$(Get-Date -AsUTC -Format 'yyyyMMddHHmmss')" - $releaseUrl = gh release create "$releaseTag" --repo Brightspace/bmx --draft --prerelease --generate-notes --title "Release $releaseTag" --target $env:GITHUB_SHA + $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 "$releaseTag" --repo Brightspace/bmx --draft --generate-notes --title "Release $releaseTag" --target $env:GITHUB_SHA + $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" } - "release_tag=$releaseTag" >> $env:GITHUB_OUTPUT + "version=$version" >> $env:GITHUB_OUTPUT $releaseId = $releaseUrl -split '/' | Select-Object -Last 1 "release_id=$releaseId" >> $env:GITHUB_OUTPUT @@ -86,27 +86,11 @@ jobs: - name: publish shell: pwsh env: - RELEASE_TAG: ${{ needs.create_release.outputs.release_tag }} + Version: ${{ needs.create_release.outputs.version }} 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 + dotnet publish -r $env:PLATFORM-x64 -o build/x64 + dotnet publish -r $env:PLATFORM-arm64 -o build/arm64 - name: check size shell: pwsh @@ -174,17 +158,11 @@ jobs: shell: pwsh env: DOCKERFILE: ${{ matrix.file }} - RELEASE_TAG: ${{ needs.create_release.outputs.release_tag }} + Version: ${{ needs.create_release.outputs.version }} 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 ` + --build-arg version=$env:Version ` -o build . - name: check size diff --git a/Dockerfile.al2 b/Dockerfile.al2 index e7719b36..ce420596 100644 --- a/Dockerfile.al2 +++ b/Dockerfile.al2 @@ -1,7 +1,7 @@ FROM public.ecr.aws/amazonlinux/amazonlinux:2 AS build -ARG version="3.0.0" -ARG information_version="v3.0.0" +ARG version="" +ENV Version=${version} RUN yum update -y && yum install -y clang openssl-devel wget tar gzip libicu @@ -21,9 +21,6 @@ RUN dotnet restore src/D2L.Bmx -r linux-x64 COPY . . RUN dotnet publish src/D2L.Bmx \ - -p:Version="$version" \ - -p:InformationVersion="$information_version" \ - -p:IncludeSourceRevisionInInformationalVersion=false \ --no-restore \ -r linux-x64 \ -o app diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 0fa0e884..6a4ca816 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -1,7 +1,7 @@ FROM amd64/alpine:3.15 AS build -ARG version="3.0.0" -ARG information_version="v3.0.0" +ARG version="" +ENV Version=${version} RUN apk update \ && apk add clang build-base bash zlib-dev icu-libs @@ -22,9 +22,6 @@ RUN dotnet restore src/D2L.Bmx -r linux-musl-x64 COPY . . RUN dotnet publish src/D2L.Bmx \ - -p:Version="$version" \ - -p:InformationVersion="$information_version" \ - -p:IncludeSourceRevisionInInformationalVersion=false \ --no-restore \ -r linux-musl-x64 \ -o app diff --git a/src/D2L.Bmx/D2L.Bmx.csproj b/src/D2L.Bmx/D2L.Bmx.csproj index 1a5ffaca..a8a3e0fb 100644 --- a/src/D2L.Bmx/D2L.Bmx.csproj +++ b/src/D2L.Bmx/D2L.Bmx.csproj @@ -8,6 +8,15 @@ true D2L.Bmx true + + + false + 3.0.0-scratch + v$(Version)