Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move versioning logic into csproj & simplify build commands #498

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 11 additions & 33 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -86,27 +86,11 @@ jobs:
- name: publish
shell: pwsh
env:
RELEASE_TAG: ${{ needs.create_release.outputs.release_tag }}
Version: ${{ needs.create_release.outputs.version }}
Comment on lines 88 to +89
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default MSBuild behaviour: if there's an environment variable named Version, its value will be automatically picked up as the property Version.
https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-properties#environment-properties

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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions Dockerfile.al2
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
7 changes: 2 additions & 5 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/D2L.Bmx/D2L.Bmx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
<InvariantGlobalization>true</InvariantGlobalization>
<RootNamespace>D2L.Bmx</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<!--
Non-release builds ("Version" not explicitly specified) will have git hash included to help us keep track,
e.g. "v3.0.0-scratch+9a2cd942ce07a1f8abccfd889d45aa55e1692d60".
Release builds (preview or real release) won't have git hash so they look cleaner.
-->
<IncludeSourceRevisionInInformationalVersion Condition="'$(Version)' != ''">false</IncludeSourceRevisionInInformationalVersion>
<Version Condition="'$(Version)' == ''">3.0.0-scratch</Version>
<InformationalVersion>v$(Version)</InformationalVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading