Skip to content

Commit

Permalink
clean up pipeline scripts and allow usage of semantic versioning (ecl…
Browse files Browse the repository at this point in the history
…ipse-aaspe#268)

Update the process for creating versions:

Update the Changelog
Move all current changes to the [Released] section in the changelog.
Determine the new version number based on semantic versioning and add the release date.
Update the Version Configuration
Use the new version number to update the current_version.cfg.
Push Changes
Push these changes to the branch you want to release from (main/develop/or your branch).
Create a New Version Tag on GitHub
Go to GitHub and create a new version tag on the branch. This tag should be the full version string, such as "0.3.0-1-aasV3-alpha-develop". The build number can be omitted in the tag name.
  • Loading branch information
Freezor authored Jun 10, 2024
1 parent c4e489c commit 8588c0b
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 161 deletions.
59 changes: 21 additions & 38 deletions .github/workflows/build-and-package-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,79 +9,62 @@ jobs:
Build-and-package-release:
runs-on: windows-latest
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v3

- name: Infer the version from the github ref
- name: Infer the version from the GitHub ref
id: inferVersion
run: |
$prefix = "refs/tags/v"
if (!${env:GITHUB_REF}.StartsWith($prefix))
{
throw "Unexpected GITHUB_REF: ${env:GITHUB_REF}"
}
$version = ${env:GITHUB_REF}.Substring($prefix.Length)
Write-Host "The version is: $version"
if ($version.Contains("'"))
{
throw "Unexpected version containing a single quote: $version"
}
if ($version.Contains('"'))
{
throw "Unexpected version containing a double quote: $version"
}
if ($version.Contains(':'))
{
throw "Unexpected version containing a full colon: $version"
}
$version = .\GetVersion.ps1 -suffix alpha
echo "::set-output name=version::$version"
shell: pwsh

Write-Output "::set-output name=version::$version"
- name: Install .NET core
uses: actions/setup-dotnet@v1
- name: Install .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'

- name: Build for the release
- name: Build for release
working-directory: src
run: .\BuildForRelease.ps1
shell: pwsh

- name: Update version numbers in project
working-directory: src
run: powershell .\BuildForRelease.ps1
run: .\UpdateProjectVersions.ps1 -version ${{ steps.inferVersion.outputs.version }}
shell: pwsh

- name: Package the release
working-directory: src
run: |
$version = '${{ steps.inferVersion.outputs.version }}'
Write-Host "Packaging for the release version: $version"
powershell .\PackageRelease.ps1 -version $version
.\PackageRelease.ps1 -version $version
shell: pwsh

- name: Rename the release assets
working-directory: ./
working-directory: .
run: |
Write-Host "Current working directory: $(Get-Location)"
$version = '${{ steps.inferVersion.outputs.version }}'
$releaseDir = Join-Path $(Get-Location) "artefacts\release\$version"
Write-Host "Release directory: $releaseDir"
if (!(Test-Path $releaseDir))
{
if (!(Test-Path $releaseDir)) {
throw "The release directory does not exist: $releaseDir"
}
$archives = Get-ChildItem $releaseDir -Filter *.zip
foreach($archive in $archives)
{
foreach($archive in $archives) {
$path = $archive.FullName
Write-Host "The path to the archive is: $path"
$nameWoExt = [io.path]::GetFileNameWithoutExtension($path)
Write-Host "The name without extension is: $nameWoExt"
$target = Join-Path $releaseDir ($nameWoExt + "." + $version + ".zip")
Write-Host "Moving: $path -> $target"
Move-Item -Path $path -Destination $target
}
shell: pwsh

- name: Upload the release assets
uses: AButler/[email protected]
Expand Down
29 changes: 15 additions & 14 deletions .github/workflows/check-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,40 @@ jobs:
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'

# Builds the project for release by executing the BuildForRelease.ps1 PowerShell script in the 'src' directory.

- name: Infer the version
id: inferVersion
run: |
$version = .\GetVersion.ps1 -suffix alpha
Write-Output "::set-output name=version::$version"
shell: pwsh

- name: Build for release
description:
working-directory: src
run: .\BuildForRelease.ps1
shell: pwsh

# Compares the output of the --help command with the README file to ensure consistency.

- name: Package
working-directory: src
run: .\PackageRelease.ps1
run: .\PackageRelease.ps1 -version ${{ steps.inferVersion.outputs.version }}
shell: pwsh
with:
suffix: alpha

# Uploads the AasxServerBlazor artifact with a timestamp to the artifacts' repository.

- name: Upload AasxServerBlazor
uses: actions/upload-artifact@v3
with:
name: AasxServerBlazor.LATEST.alpha.${{ steps.setTimestamp.outputs.timestamp }}
name: AasxServerBlazor.LATEST.${{ steps.inferVersion.outputs.version }}.${{ steps.setTimestamp.outputs.timestamp }}
path: artefacts/release/LATEST.alpha/AasxServerBlazor.zip

# Uploads the AasxServerAspNetCore artifact with a timestamp to the artifacts' repository.

- name: Upload AasxServerAspNetCore
uses: actions/upload-artifact@v3
with:
name: AasxServerAspNetCore.LATEST.alpha.${{ steps.setTimestamp.outputs.timestamp }}
name: AasxServerAspNetCore.LATEST.${{ steps.inferVersion.outputs.version }}.${{ steps.setTimestamp.outputs.timestamp }}
path: artefacts/release/LATEST.alpha/AasxServerAspNetCore.zip

# Uncomment the following steps if you need to upload the AasxServerWindows artifact
# - name: Upload AasxServerWindows
# uses: actions/upload-artifact@v3
# with:
# name: AasxServerWindows.LATEST.alpha.${{ steps.setTimestamp.outputs.timestamp }}
# name: AasxServerWindows.LATEST.${{ steps.inferVersion.outputs.version }}.${{ steps.setTimestamp.outputs.timestamp }}
# path: artefacts/release/LATEST.alpha/AasxServerWindows.zip
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,42 @@ An example GraphQL query is:
If you want to create a registry and also automatically POST to it, please take a look at
our [GitHub issues](https://github.com/admin-shell-io/aasx-server/issues/189) page.

## CREATE NEW RELEASES

We've transitioned to [semantic versioning](https://semver.org) for better version distinctness. All versions follow this schema:

```
<major>.<minor>.<patch>-<buildnumber>-<AAS Schema Version>-<alpha>-<stable|latest|develop>
```

- **buildnumber**: An incremented value for each build, important for development or latest releases to distinguish builds even if there's no new version number.
- **AAS Schema Version**: Indicates the AAS main schema used in this version.
- **alpha**: Indicates this is still an alpha build, not a finished release.
- **stable**: The latest stable release, where the main features are confirmed working.
- **latest**: The most recent build on the main branch. It's relatively stable but may have some issues.
- **develop**: A build from a branch other than main or develop. It's for testing and may be unstable.

### Release a New Version

With the change to semantic versioning, the release process has been updated as well.

To release a new version, follow these steps:

1. **Update the Changelog**
- Move all current changes to the [Released] section in the [changelog](CHANGELOG.md).
- Determine the new version number based on semantic versioning and add the release date.
2. **Update the Version Configuration**
- Use the new version number to update the [current_version.cfg](src/current_version.cfg).
3. **Push Changes**
- Push these changes to the branch you want to release from (main/develop/or your branch).
4. **Create a New Version Tag on GitHub**
- Go to GitHub and create a new version tag on the branch. This tag should be the full version string, such as "0.3.0-1-aasV3-alpha-develop". The build number can be omitted in the tag name.

### Example Version Tags
- `1.0.0-1-aasV3-alpha-develop`: An alpha build on a develop branch with build number 1.
- `1.0.0-2-aasV3-alpha-stable`: A stable release with build number 2.
- `1.0.0-3-aasV3-alpha-latest`: The latest build on the main branch with build number 3.

## OLD DOCUMENTATION

This documentation will be updated to V3 soon.
Expand Down
51 changes: 21 additions & 30 deletions src/BuildForRelease.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,47 @@

<#
.DESCRIPTION
This script builds the solution for debugging (manual or automatic testing).
This script builds the solution for debugging (manual or automatic testing) or cleans up the previous build.
#>

# Set error action preference to stop on errors.
$ErrorActionPreference = "Stop"

# Import necessary functions from the Common module.
Import-Module (Join-Path $PSScriptRoot Common.psm1) -Function AssertDotnet, GetArtefactsDir

function CopyContentForDemo($Destination)
{
function CopyContentForDemo($Destination) {
$contentForDemoDir = Join-Path (Split-Path -Parent $PSScriptRoot) "content-for-demo"
if (!(Test-Path $contentForDemoDir))
{
if (!(Test-Path $contentForDemoDir)) {
throw "The directory with the content for demo does not exist: $contentForDemoDir"
}

Write-Host "Copying content for demo from $contentForDemoDir to: $Destination"

Get-ChildItem -Path $contentForDemoDir | Copy-Item -Destination $Destination -Recurse -Container -Force
}

function Main
{
function Main {
# Change to the script root directory.
Set-Location $PSScriptRoot

# Define the base build directory.
$baseBuildDir = Join-Path $(GetArtefactsDir) "build" | Join-Path -ChildPath "Release"

if ($clean)
{
if ($clean) {
# Clean up previous build if requested.
Write-Host "dotnet clean'ing ..."
Write-Host "Cleaning up previous build..."
dotnet clean
if ($LASTEXITCODE -ne 0)
{
throw "Failed to dotnet clean."
if ($LASTEXITCODE -ne 0) {
throw "Failed to clean the project."
}

Write-Host "Removing the build directory: $baseBuildDir"
Remove-Item -LiteralPath $baseBuildDir -Force -Recurse
}
else
{
if (Test-Path $baseBuildDir) {
Remove-Item -LiteralPath $baseBuildDir -Force -Recurse
} else {
Write-Host "Build directory does not exist: $baseBuildDir"
}
} else {
# Ensure dotnet is installed.
AssertDotnet

Expand All @@ -59,16 +56,13 @@ function Main
"AasxServerAspNetCore"
)

foreach ($target in $dotnetTargets)
{
foreach ($target in $dotnetTargets) {
$buildDir = Join-Path $baseBuildDir $target

Write-Host "Publishing with dotnet $target to: $buildDir"

Write-Host "Publishing $target to: $buildDir"
dotnet publish -c Release -o $buildDir $target
if ($LASTEXITCODE -ne 0)
{
throw "Failed to dotnet publish: $target"
if ($LASTEXITCODE -ne 0) {
throw "Failed to publish the project: $target"
}

# Copy content for demo to the build directory.
Expand All @@ -79,11 +73,8 @@ function Main

# Store the current location, execute the main function, and return to the original location.
$previousLocation = Get-Location
try
{
try {
Main
}
finally
{
} finally {
Set-Location $previousLocation
}
78 changes: 78 additions & 0 deletions src/BuildVersionNumber.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
param(
[Parameter(HelpMessage = "Suffix to be appended to the version (e.g., alpha, beta)", Mandatory = $false)]
[string]
$suffix = "alpha"
)

# Set error action preference to stop on errors.
$ErrorActionPreference = "Stop"

function GetNextBuildNumber
{
# Read the current build number from the file.
$currentBuild = Get-Content (Join-Path $PSScriptRoot "current_build_number.cfg") | ForEach-Object { $_.Trim() }

# Increment the build number and save it back to the file.
$nextBuild = [int]$currentBuild + 1
$nextBuild | Set-Content (Join-Path $PSScriptRoot "current_build_number.cfg")

# Return the incremented build number.
return $nextBuild
}

function GetVersionCore
{
# Read the current version from the file.
$versionCore = Get-Content (Join-Path $PSScriptRoot "current_version.cfg") | ForEach-Object { $_.Trim() }

# Return the version core.
return $versionCore
}

function GetBuildSuffix
{
# Determine if the build is on the main or release branch.
$branch = git branch --show-current 2> $null # Suppress errors if not in a Git repository
if (-not $?)
{
Write-Host "Not in a Git repository. Assuming develop branch."
return "develop"
}

if ($branch -eq "main")
{
return "latest"
}
elseif ($branch -eq "release")
{
return "stable"
}
else
{
Write-Host "Not main or release branch. Assuming develop branch."
return "develop"
}
}

function GetVersion
{
# Get the version core from the file.
$versionCore = GetVersionCore

# Get the build suffix based on the branch.
$buildSuffix = GetBuildSuffix

# Get the next build number.
$buildNumber = GetNextBuildNumber

$aasmodel = "aasV3"

# Construct the semantic version.
$semanticVersion = "$versionCore-$buildNumber-$aasmodel-$suffix-$buildSuffix"

return $semanticVersion
}

# Generate the version and print it to output.
$version = GetVersion
Write-Output $version
Loading

0 comments on commit 8588c0b

Please sign in to comment.