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 diff --git a/.github/actions/pr-lint/action.yml b/.github/actions/pr-lint/action.yml new file mode 100644 index 0000000..c3468d2 --- /dev/null +++ b/.github/actions/pr-lint/action.yml @@ -0,0 +1,42 @@ +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 + with: + github-token: ${{ inputs.github-token }} + + # 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/new-version.yml b/.github/workflows/new-version.yml new file mode 100644 index 0000000..666b059 --- /dev/null +++ b/.github/workflows/new-version.yml @@ -0,0 +1,60 @@ +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_PAT }} + + 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 + do-push: false # let's first see if this works + nuget-feed-access-token: ${{ secrets.NUGET_API_KEY }} 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 }} 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', + ], +}; diff --git a/src/generator/generator.csproj b/src/generator/generator.csproj index 4cfdf22..df27129 100644 --- a/src/generator/generator.csproj +++ b/src/generator/generator.csproj @@ -11,15 +11,26 @@ - Runedur.Generator + Runedur Runedur true false true true true + Runedur + Pingvinen + Runedur + ORM;Postgres;Timescaledb + 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/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 {{ diff --git a/src/unit-tests/unit-tests.csproj b/src/unit-tests/unit-tests.csproj index cb30427..91c0542 100644 --- a/src/unit-tests/unit-tests.csproj +++ b/src/unit-tests/unit-tests.csproj @@ -14,6 +14,7 @@ + @@ -26,6 +27,11 @@ + + + bin/$(Configuration)/$(MSBuildProjectName)/ + + 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"