From 793765fd74656bfb00878ab19b0b9b1fe431d9cf Mon Sep 17 00:00:00 2001 From: Patrick Boisen Date: Sat, 19 Apr 2025 21:10:46 +0200 Subject: [PATCH 01/13] Add a PR linting workflow This is to make it possible to detect issues before applying automagic semantic versioning. --- .github/actions/pr-lint/action.yml | 40 ++++++++++++++++++++++++ .github/actions/pr-lint/title/action.yml | 30 ++++++++++++++++++ .github/workflows/pr-lint.yml | 30 ++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 .github/actions/pr-lint/action.yml create mode 100644 .github/actions/pr-lint/title/action.yml create mode 100644 .github/workflows/pr-lint.yml diff --git a/.github/actions/pr-lint/action.yml b/.github/actions/pr-lint/action.yml new file mode 100644 index 0000000..f0e68b4 --- /dev/null +++ b/.github/actions/pr-lint/action.yml @@ -0,0 +1,40 @@ +name: pr-lint +description: Lint the PR according to our rules + +inputs: + github-token: + description: "Github token from the workflow" + required: true + +runs: + using: "composite" + steps: + - name: Lint PR title + id: lint-pr-title + uses: ./.github/actions/pr-lint/title + + # Report on the error of the preceding step + - if: always() && (steps.lint-pr-title.outputs.error_message != null) + uses: marocchino/sticky-pull-request-comment@v2 + with: + GITHUB_TOKEN: ${{ inputs.github-token }} + header: pr-title-lint-error + message: | + The PR title must follow the [Conventional Commits specification(https://www.conventionalcommits.org/en/v1.0.0/) and this PR does not 😔 + + A few examples: + feat(gh-123): heroic feature added + fix(GH-653): santa's junk + + Details from the linter: + ``` + ${{ steps.lint-pr-title.outputs.error_message }} + ``` + + # Delete previous PR comment when the linter is happy + - if: ${{ steps.lint-pr-title.outputs.error_message == null }} + uses: marocchino/sticky-pull-request-comment@v2 + with: + GITHUB_TOKEN: ${{ inputs.github-token }} + header: pr-title-lint-error + delete: true diff --git a/.github/actions/pr-lint/title/action.yml b/.github/actions/pr-lint/title/action.yml new file mode 100644 index 0000000..abbf020 --- /dev/null +++ b/.github/actions/pr-lint/title/action.yml @@ -0,0 +1,30 @@ +name: pr-lint/title +description: Lint the PR title according to semantic commit rules + +inputs: + github-token: + description: "Github token from the workflow" + required: true + +outputs: + error_message: + description: Error message from the validation of the PR title + value: ${{ steps.lint-pr-title.outputs.error_message }} + +runs: + using: "composite" + steps: + - name: Validate PR title + id: lint-pr-title + uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ inputs.github-token }} + with: + # Configure which scopes are allowed (newline-delimited). + # These are regex patterns auto-wrapped in `^ $`. + scopes: | + deps-dev + deps + gh-\d+ + GH-\d+ + requireScope: true diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml new file mode 100644 index 0000000..8a61f05 --- /dev/null +++ b/.github/workflows/pr-lint.yml @@ -0,0 +1,30 @@ +name: "PR lint" + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + pull_request: + types: + - opened + - edited + - synchronize + - reopened + branches: + - main + +permissions: + id-token: write + contents: read + pull-requests: write + +jobs: + pr-lint: + name: Check PR title + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/pr-lint + with: + github-token: ${{ secrets.GITHUB_TOKEN }} From a71d1e947c317e7500d2e204011ebb8422a77e4e Mon Sep 17 00:00:00 2001 From: Patrick Boisen Date: Sat, 19 Apr 2025 21:18:09 +0200 Subject: [PATCH 02/13] Pass the gh token to the internal action --- .github/actions/pr-lint/action.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/actions/pr-lint/action.yml b/.github/actions/pr-lint/action.yml index f0e68b4..0854d7d 100644 --- a/.github/actions/pr-lint/action.yml +++ b/.github/actions/pr-lint/action.yml @@ -12,6 +12,8 @@ runs: - name: Lint PR title id: lint-pr-title uses: ./.github/actions/pr-lint/title + with: + github-token: ${{ inputs.github-token }} # Report on the error of the preceding step - if: always() && (steps.lint-pr-title.outputs.error_message != null) From e5675a62cf8021ff4f9e7898f808dcea238b61ac Mon Sep 17 00:00:00 2001 From: Patrick Boisen Date: Sat, 19 Apr 2025 21:20:07 +0200 Subject: [PATCH 03/13] Tweak the invalid title message a bit --- .github/actions/pr-lint/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/pr-lint/action.yml b/.github/actions/pr-lint/action.yml index 0854d7d..c3468d2 100644 --- a/.github/actions/pr-lint/action.yml +++ b/.github/actions/pr-lint/action.yml @@ -25,8 +25,8 @@ runs: The PR title must follow the [Conventional Commits specification(https://www.conventionalcommits.org/en/v1.0.0/) and this PR does not 😔 A few examples: - feat(gh-123): heroic feature added - fix(GH-653): santa's junk + - feat(gh-123): heroic feature added + - fix(GH-653): santa's junk Details from the linter: ``` From 84483913f83bb842d123ad62583c20f2762da1a3 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 19 Apr 2025 21:24:01 +0200 Subject: [PATCH 04/13] Add version.sh script --- version.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 version.sh diff --git a/version.sh b/version.sh new file mode 100644 index 0000000..3e3cf68 --- /dev/null +++ b/version.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +if [ $# -ne 1 ]; then + echo "Usage: $0 NEW_VERSION_FROM_SEMANTIC_RELEASE" + exit 1 +fi + +VERSION="$1" + +find . -type f -name '*.csproj' -print0 | xargs -0 -I {} dotnet version --skip-vcs --project-file {} "$VERSION" From c84da9f823f3c8980d69e216c8d48c85d3ad2eb4 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 19 Apr 2025 21:25:14 +0200 Subject: [PATCH 05/13] Add release.config.mjs --- release.config.mjs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 release.config.mjs diff --git a/release.config.mjs b/release.config.mjs new file mode 100644 index 0000000..9a30cde --- /dev/null +++ b/release.config.mjs @@ -0,0 +1,30 @@ +/** + * @type {import('semantic-release').GlobalConfig} + */ +export default { + branches: ['main'], + plugins: [ + [ + "@semantic-release/commit-analyzer", + { + "releaseRules": [ + {"type": "chore", "release": "patch"}, + ], + } + ], + '@semantic-release/release-notes-generator', + [ + "@semantic-release/exec", + { + "prepareCmd": "./version.sh ${nextRelease.version}", + } + ], + [ + '@semantic-release/git', + { + message: 'chore(release): v${nextRelease.version}', + }, + ], + '@semantic-release/github', + ], +}; From 9dccdc6699bac84f62f94ab9cc5fc81aecf60afb Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 19 Apr 2025 21:32:01 +0200 Subject: [PATCH 06/13] Add new-version.yml workflow --- .github/workflows/new-version.yml | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 .github/workflows/new-version.yml diff --git a/.github/workflows/new-version.yml b/.github/workflows/new-version.yml new file mode 100644 index 0000000..af8b1d2 --- /dev/null +++ b/.github/workflows/new-version.yml @@ -0,0 +1,62 @@ +name: "Create new version" + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: true + +on: + workflow_dispatch: + +jobs: + new-version: + runs-on: ubuntu-latest + outputs: + new-release-version: ${{ steps.semantic.outputs.new_release_version }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false + + - id: setup + uses: ./.github/actions/dotnet-setup + name: setup and configure dotnet + with: + dotnet-versions: 8.x + + - id: dotnet-version + name: Install dotnet version + shell: bash + run: | + dotnet tool install --global dotnet-version-cli --version 3.0.3 + + - name: Semantic Release + id: semantic + uses: cycjimmy/semantic-release-action@v4 + with: + extra_plugins: | + @semantic-release/exec + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + + publish-nuget-package: + runs-on: ubuntu-latest + needs: [ new-version ] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - id: setup + uses: ./.github/actions/dotnet-setup@v2 + name: setup and configure dotnet + with: + dotnet-versions: 8.x + + - uses: ./.github/actions/dotnet-nuget + name: Publish nuget package + with: + target-dir: src/generator + set-new-version: ${{ needs.new-version.outputs.new-release-version }} + do-push: false # let's first see if this works + nuget-feed-access-token: "wait-for-it" # ${{ secrets.PACKAGE_PUSH_TOKEN }} + nuget-feed-uri: "" From 0411107faec873700043492c163d12c9ee6fc95e Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 19 Apr 2025 21:35:40 +0200 Subject: [PATCH 07/13] Add dotnet-nuget action --- .github/actions/dotnet-nuget/action.yml | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/actions/dotnet-nuget/action.yml diff --git a/.github/actions/dotnet-nuget/action.yml b/.github/actions/dotnet-nuget/action.yml new file mode 100644 index 0000000..baa79fd --- /dev/null +++ b/.github/actions/dotnet-nuget/action.yml @@ -0,0 +1,46 @@ +name: dotnet-nuget +description: Dotnet nuget pack and publish action. Depends on dotnet-setup action. + +inputs: + target-dir: + description: The build target directory + required: true + do-push: + description: Push the package to the nuget feed + required: false + default: 'true' + nuget-feed-access-token: + description: the access token for the nuget feed + required: false + type: string + default: '' + nuget-feed-uri: + description: the nuget feed to use + required: false + default: 'https://api.nuget.org/v3/index.json' + type: string + +runs: + using: 'composite' + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 100 + fetch-tags: true + + - id: dotnet-build + name: Dotnet build + run: dotnet build --configuration Release ${{ inputs.target-dir }} + shell: bash + + - id: dotnet-pack + name: Dotnet pack + run: dotnet pack --configuration Release ${{ inputs.target-dir }} + shell: bash + + - id: dotnet-publish + if: inputs.do-push == 'true' + name: Dotnet publish + run: dotnet nuget push "${{ inputs.target-dir }}/bin/Release/*.nupkg" --api-key ${{ inputs.nuget-feed-access-token }} --source ${{ inputs.nuget-feed-uri }} + shell: bash From 478df8ced6ed86296aa4bafb6fccf4cf58ffd975 Mon Sep 17 00:00:00 2001 From: Patrick Boisen Date: Sat, 19 Apr 2025 21:49:03 +0200 Subject: [PATCH 08/13] Tweaks to the new-version workflow --- .github/workflows/new-version.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/new-version.yml b/.github/workflows/new-version.yml index af8b1d2..886fb52 100644 --- a/.github/workflows/new-version.yml +++ b/.github/workflows/new-version.yml @@ -37,7 +37,7 @@ jobs: extra_plugins: | @semantic-release/exec env: - GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN_PAT }} publish-nuget-package: runs-on: ubuntu-latest @@ -56,7 +56,5 @@ jobs: name: Publish nuget package with: target-dir: src/generator - set-new-version: ${{ needs.new-version.outputs.new-release-version }} do-push: false # let's first see if this works nuget-feed-access-token: "wait-for-it" # ${{ secrets.PACKAGE_PUSH_TOKEN }} - nuget-feed-uri: "" From 8cf7be5ca6569a9115f36858bc8ce8328b557ba8 Mon Sep 17 00:00:00 2001 From: Patrick Boisen Date: Sat, 19 Apr 2025 21:58:08 +0200 Subject: [PATCH 09/13] Get nuget token from secrets --- .github/workflows/new-version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/new-version.yml b/.github/workflows/new-version.yml index 886fb52..666b059 100644 --- a/.github/workflows/new-version.yml +++ b/.github/workflows/new-version.yml @@ -57,4 +57,4 @@ jobs: with: target-dir: src/generator do-push: false # let's first see if this works - nuget-feed-access-token: "wait-for-it" # ${{ secrets.PACKAGE_PUSH_TOKEN }} + nuget-feed-access-token: ${{ secrets.NUGET_API_KEY }} From 48aef7551dfa250a53e19165f8cf644f21935afa Mon Sep 17 00:00:00 2001 From: Patrick Boisen Date: Sat, 19 Apr 2025 22:07:51 +0200 Subject: [PATCH 10/13] Set some more package related properties --- src/generator/generator.csproj | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/generator/generator.csproj b/src/generator/generator.csproj index 4cfdf22..adfe90e 100644 --- a/src/generator/generator.csproj +++ b/src/generator/generator.csproj @@ -11,13 +11,18 @@ - Runedur.Generator + Runedur Runedur true false true true true + Runedur + Pingvinen + Runedur + ORM;Postgres;Timescaledb + https://github.com/pingvinen/runedur-orm From 9b75372217e306332c43a481a06275e148d87cf6 Mon Sep 17 00:00:00 2001 From: Patrick Boisen Date: Sat, 19 Apr 2025 22:14:12 +0200 Subject: [PATCH 11/13] Update generator attribute value in test --- src/unit-tests/EntityAttributeGeneratorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unit-tests/EntityAttributeGeneratorTests.cs b/src/unit-tests/EntityAttributeGeneratorTests.cs index 019f3d0..621413e 100644 --- a/src/unit-tests/EntityAttributeGeneratorTests.cs +++ b/src/unit-tests/EntityAttributeGeneratorTests.cs @@ -24,7 +24,7 @@ namespace Runedur /// Marks a class as an entity that Runedur should /// consider during code generation /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Runedur.Generator"", ""{version}"")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute(""Runedur"", ""{version}"")] [global::System.AttributeUsage(global::System.AttributeTargets.Class, AllowMultiple = false)] internal sealed class RunedurEntityAttribute : global::System.Attribute {{ From 0b6995b9da46ff24d858ecdb8c6ef4be405f4ce5 Mon Sep 17 00:00:00 2001 From: Patrick Boisen Date: Tue, 29 Apr 2025 13:22:46 +0200 Subject: [PATCH 12/13] Solve Workspaces version warning --- src/unit-tests/unit-tests.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/unit-tests/unit-tests.csproj b/src/unit-tests/unit-tests.csproj index cb30427..58eb6e7 100644 --- a/src/unit-tests/unit-tests.csproj +++ b/src/unit-tests/unit-tests.csproj @@ -14,6 +14,7 @@ + From b8df1775773337db2f2297434d779131219d4621 Mon Sep 17 00:00:00 2001 From: Patrick Boisen Date: Tue, 29 Apr 2025 13:27:54 +0200 Subject: [PATCH 13/13] Use different output paths for the projects This will hopefully avoid concurrent builds needing the same files and thereby deadlocking. --- src/generator/generator.csproj | 6 ++++++ src/integration-tests/integration-tests.csproj | 5 +++++ src/unit-tests/unit-tests.csproj | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/src/generator/generator.csproj b/src/generator/generator.csproj index adfe90e..df27129 100644 --- a/src/generator/generator.csproj +++ b/src/generator/generator.csproj @@ -25,6 +25,12 @@ https://github.com/pingvinen/runedur-orm + + + bin/$(Configuration)/$(MSBuildProjectName)/ + + + diff --git a/src/integration-tests/integration-tests.csproj b/src/integration-tests/integration-tests.csproj index aa7f0d6..7dd07a2 100644 --- a/src/integration-tests/integration-tests.csproj +++ b/src/integration-tests/integration-tests.csproj @@ -23,6 +23,11 @@ + + + bin/$(Configuration)/$(MSBuildProjectName)/ + + diff --git a/src/unit-tests/unit-tests.csproj b/src/unit-tests/unit-tests.csproj index 58eb6e7..91c0542 100644 --- a/src/unit-tests/unit-tests.csproj +++ b/src/unit-tests/unit-tests.csproj @@ -27,6 +27,11 @@ + + + bin/$(Configuration)/$(MSBuildProjectName)/ + +