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

ci: improve release process #15

Merged
merged 17 commits into from
Mar 18, 2023
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
9 changes: 8 additions & 1 deletion .autorc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
"plugins": [
"git-tag",
"first-time-contributor",
"released"
"released",
[
"upload-assets",
[
"./android-build.zip",
"./windows-build.zip"
]
]
],
"owner": "Michaelvsk",
"repo": "GameDb",
Expand Down
133 changes: 4 additions & 129 deletions .github/workflows/build-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,132 +13,7 @@ env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true

jobs:
build:
name: Build
runs-on: windows-latest
defaults:
run:
shell: pwsh
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis


# Versioning
- name: Install .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.x

- name: Versioning project's csproj file
run: |

$cprojFiles = @( `
"./GameDb/GameDb.csproj",
"./GameDb.Common/GameDb.Common.csproj",
"./GameDb.Core/GameDb.Core.csproj",
"./GameDb.DAL/GameDb.DAL.csproj"
)

foreach($proj in $cprojFiles) {
$versionNo = Select-Xml -XPath "/Project/PropertyGroup/AssemblyVersion" -Path $proj | %{$_.node.InnerXML}

# if fails to extract version number, then let workflow fail
Write-Host "Extracted version is: $versionNo"
if ($versionNo -eq $null) {
Write-Host "::error ::Failed to read version number from project file."
exit 1
}

# append build number if requested
if ($env:GITHUB_REF_NAME -ne "main") {
Write-Host "Appending build number to version"
$versionNo="$versionNo.$env:GITHUB_RUN_ID"
}
Write-Host "Using version '$versionNo' for this build artifact"
Add-Content $env:GITHUB_ENV "artifact_version=$versionNo"
}


# Prepare SonarCloud
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v3
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner

# Prepare test coverage analysis
- name: Cache DotNet Coverage Tool
id: cache-dotcover
uses: actions/cache@v3
with:
path: .\.net-coverage
key: ${{ runner.os }}-dotcover
restore-keys: ${{ runner.os }}-dotcover
- name: Install DotNet Coverage Tool
if: steps.cache-dotcover.outputs.cache-hit != 'true'
run: |
New-Item -Path .\.net-coverage -ItemType Directory
dotnet tool update JetBrains.dotCover.GlobalTool --tool-path ./.net-coverage

# Build Project
- name: Cache nuget packages-
uses: actions/cache@v3
id: cache-nuget
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-

#- name: Install Workloads
# run: |
# dotnet workload install maui maui-android maui-ios maui-maccatalyst maui-windows

- name: Install Dependencies
if: steps.cache-nuget.outputs.cache-hit != 'true'
run: dotnet restore --locked-mode

- name: Init SonarCloud Analyzer
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: >
.\.sonar\scanner\dotnet-sonarscanner begin
/k:"Michaelvsk_GameDb"
/o:"github-michaelvsk"
/d:sonar.login="${{ secrets.SONAR_TOKEN }}"
/d:sonar.host.url="https://sonarcloud.io"
/v:="${{ env.artifact_version }}"
/d:sonar.cs.dotcover.reportsPaths=dotCover.Output.html

- name: Build Project
run: dotnet build -c Release --no-incremental

- name: Calculate UnitTests Code Coverage
run: .\.net-coverage\dotnet-dotcover test --dcReportType=HTML --dcXml=dotCoverConfig.xml

- name: Finish SonarCloud Analyzer
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: .\.sonar\scanner\dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
Build:
uses: ./.github/workflows/wf-build.yaml
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
86 changes: 77 additions & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
name: Release
concurrency: release
concurrency: ${{ github.ref }}

on:
workflow_dispatch:
push:
branches: [ main ]

jobs:
release:
name: Release
if: false == endsWith(github.event.head_commit.message, '[release]')
versioning:
name: Bump Version
runs-on: ubuntu-latest

outputs:
version: ${{ steps.versioning.outputs.version }}
commit: ${{ steps.versioning.outputs.commit }}
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -26,7 +27,12 @@ jobs:
# Tool to compute version based on Github PR labels
- name: Install auto versioning
run: >
npm install --global [email protected] @auto-it/[email protected] @auto-it/[email protected] @auto-it/[email protected]
npm install --global
[email protected]
@auto-it/[email protected]
@auto-it/[email protected]
@auto-it/[email protected]
@auto-it/[email protected]

# dotnet version relies on .NET Core 2.1 (TODO maybe fork project dotnet version as .NET 2.1 reached EOL)
- uses: actions/setup-dotnet@v3
Expand Down Expand Up @@ -54,9 +60,14 @@ jobs:
if [ ! -z "$VERSION" ]; then
dotnet version $VERSION
if VERSION_NO=$(xmlstarlet sel -t -m '/Project/PropertyGroup/AssemblyVersion' -v . < ./GameDb/GameDb.csproj 2>&1); then
echo "Extracted version number is ${VERSION_NO}"
git commit -a -m "chore(release): $VERSION_NO [skip ci]"
auto shipit
echo "Extracted version number is: ${VERSION_NO}"
echo "git status:"
git status
git commit -a -m "chore(release): Bump assembly versions ${VERSION_NO} [skip ci]"

echo "version=${VERSION_NO}" >> "$GITHUB_OUTPUT"
echo "commit=`git rev-parse --verify HEAD`" >> "$GITHUB_OUTPUT"
git push
else
echo "Extracting version from csproj file failed. Error: ${VERSION_NO}"
exit 1
Expand All @@ -66,3 +77,60 @@ jobs:
fi
env:
GITHUB_TOKEN: ${{secrets.GH_ADMIN_TOKEN}}

build:
uses: ./.github/workflows/wf-build.yaml
needs: versioning
name: Build .NET MAUI App
with:
append-build-number: false
ref: ${{ needs.versioning.outputs.commit }}
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

release:
name: Create Release
needs: [versioning, build]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ needs.versioning.outputs.commit }}
token: ${{ secrets.GH_ADMIN_TOKEN }}

- name: Setup GIT
run: |
git config user.email "[email protected]"
git config user.name "$GITHUB_ACTOR"

# Compute version based on Github PR labels
- name: Install auto versioning
run: >
npm install --global
[email protected]
@auto-it/[email protected]
@auto-it/[email protected]
@auto-it/[email protected]
@auto-it/[email protected]

- uses: actions/download-artifact@v3
with:
name: android-build
path: android-artifact

- uses: actions/download-artifact@v3
with:
name: windows-build
path: windows-artifact

- name: ZIP Windows Build
run: zip -r -9 windows-build.zip windows-artifact

- name: ZIP Android Build
run: zip -r -9 android-build.zip android-artifact

- name: Testing release
run: auto shipit --only-graduate-with-release-label
env:
GH_TOKEN: ${{secrets.GH_ADMIN_TOKEN}}
Loading