From d39768be48f875d7529bb755f214ed831374f1e9 Mon Sep 17 00:00:00 2001 From: Prokop Simek Date: Mon, 13 Nov 2023 10:49:11 +0100 Subject: [PATCH] feat: add Dart and C# to supported technologies --- .../actions/publish-csharp-nuget/action.yml | 22 +++++++++++++++++++ .../actions/publish-dart-pubdev/action.yml | 17 ++++++++++++++ README.md | 4 ++-- action.yml | 21 +++++++++++++++++- src/index.ts | 14 +++++++++++- 5 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 .github/actions/publish-csharp-nuget/action.yml create mode 100644 .github/actions/publish-dart-pubdev/action.yml diff --git a/.github/actions/publish-csharp-nuget/action.yml b/.github/actions/publish-csharp-nuget/action.yml new file mode 100644 index 0000000..a403c6c --- /dev/null +++ b/.github/actions/publish-csharp-nuget/action.yml @@ -0,0 +1,22 @@ +# This workflow will publish a package to nuget.org when a release is created + +name: Publish to nuget.org +description: This workflow will publish a package to nuget.org when a release is created + +inputs: + package-path: + description: 'The path to the package directory' + required: false + default: '.' + +runs: + using: composite + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-dotnet@v3 + - env: + NUGET_DIR: ${{ env.NUGET_DIR }} + NUGET_APIKEY: ${{ env.NUGET_APIKEY }} + run: dotnet nuget push "${{ env.NUGET_DIR }}/*.nupkg" --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json + shell: bash + working-directory: ${{ inputs.package-path }} \ No newline at end of file diff --git a/.github/actions/publish-dart-pubdev/action.yml b/.github/actions/publish-dart-pubdev/action.yml new file mode 100644 index 0000000..1b4ddb5 --- /dev/null +++ b/.github/actions/publish-dart-pubdev/action.yml @@ -0,0 +1,17 @@ +# This workflow will publish a package to pub.dev when a release is created + +name: Publish to pub.dev +description: This workflow will publish a package to pub.dev when a release is created + +inputs: + package-path: + description: 'The path to the package directory' + required: false + default: '.' + +runs: + using: composite + steps: + - uses: actions/checkout@v3 + - uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1 + working-directory: ${{ inputs.package-path }} \ No newline at end of file diff --git a/README.md b/README.md index 268efcc..7802f54 100644 --- a/README.md +++ b/README.md @@ -25,11 +25,11 @@ You can get your package published in a few minutes and you won't have to worry - ✅ node - ✅ php - ✅ ruby +- ✅ C# +- ✅ dart ## Please request other package types in the issues -- 🛠️ .NET -- 🛠️ dart - 🛠️ elixir - 🛠️ go - 🛠️ helm diff --git a/action.yml b/action.yml index 3f6ba52..7c17232 100644 --- a/action.yml +++ b/action.yml @@ -144,6 +144,7 @@ runs: # Validate the action parameters - name: GH Action Validation + id: gh-action-validation run: 'node dist/index.js --package-name ${{ inputs.package-name }} --release-type ${{ inputs.release-type }}' shell: bash @@ -152,7 +153,7 @@ runs: id: release-please uses: google-github-actions/release-please-action@v3 with: - release-type: ${{ inputs.release-type }} + release-type: ${{ steps.gh-action-validation.outputs.release-please-release-type }} package-name: ${{ inputs.package-name }} token: ${{ inputs.token }} fork: ${{ inputs.fork }} @@ -230,6 +231,24 @@ runs: PACKAGIST_USERNAME: ${{ env.PACKAGIST_USERNAME }} PACKAGIST_TOKEN: ${{ env.PACKAGIST_TOKEN }} + # Publishing the package to nuget.org if the release is a C# package + - name: Publish to nuget.org + if: contains(github.event.head_commit.message, 'chore(release)') && inputs.release-type == 'csharp' + uses: ./.github/actions/publish-csharp-nuget + with: + package-path: ${{ inputs.package-path }} + env: + NUGET_DIR: ${{ env.NUGET_DIR }} + NUGET_APIKEY: ${{ env.NUGET_APIKEY }} + + # Publishing the package to pub.dev if the release is a Dart package + - name: Publish to pub.dev + # if: contains(github.event.head_commit.message, 'v[0-9]+.[0-9]+.[0-9]+*') && inputs.release-type == 'dart' + if: contains(github.event.head_commit.message, 'chore(release)') && inputs.release-type == 'dart' + uses: ./.github/actions/publish-dart-pubdev + with: + package-path: ${{ inputs.package-path }} + # TODO: Add publishing to other package managers # ... diff --git a/src/index.ts b/src/index.ts index 2a3dcdc..0b912fb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,8 +2,9 @@ import * as core from '@actions/core'; import minimist from 'minimist'; // https://github.com/google-github-actions/release-please-action/tree/main#release-types-supported -const VALID_RELEASE_TYPES = [ +const VALID_RELEASE_PLEASE_RELEASE_TYPES = [ 'elixir', + 'dart', 'go', 'helm', 'java', @@ -19,6 +20,10 @@ const VALID_RELEASE_TYPES = [ 'terraform-module', ]; +// custom release types that release-please doesn't support +// are rewritten to a different for publish action +const VALID_RELEASE_TYPES = [...VALID_RELEASE_PLEASE_RELEASE_TYPES, 'csharp']; + try { core.info(`Validating input parameters...`); @@ -39,6 +44,13 @@ try { throw new Error(`Package name is required.`); } + // rewrite custom release types to a different release type + if (!VALID_RELEASE_PLEASE_RELEASE_TYPES.includes(releaseType)) { + core.setOutput('release-please-release-type', 'simple'); + } else { + core.setOutput('release-please-release-type', releaseType); + } + core.notice(`Configuration valid. Processing release for package '${packageName}' with release type '${releaseType}'.`); // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (error: any) {