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

feat: add Dart and C# to supported technologies #14

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
22 changes: 22 additions & 0 deletions .github/actions/publish-csharp-nuget/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
17 changes: 17 additions & 0 deletions .github/actions/publish-dart-pubdev/action.yml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 }}
Expand Down Expand Up @@ -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'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U toho Dartu to budeme muset udělat jinak. pub.dev totiž vyžaduje publish jen z GIT tagu: https://dart.dev/tools/pub/automated-publishing#publishing-packages-using-github-actions

info Note: Pub.dev only allows automated publishing from GitHub Actions when the workflow is triggered by pushing a git tag to GitHub. Pub.dev rejects publishing from GitHub Actions triggered without a tag. This ensures that new versions cannot be published by events that should never trigger publishing.

viz https://github.com/ButterCMS/buttercms-dart/pull/9/files#diff-551d1fcf87f78cc3bc18a7b332a4dc5d8773a512062df881c5aba28a6f5c48d7

uses: ./.github/actions/publish-dart-pubdev
with:
package-path: ${{ inputs.package-path }}

# TODO: Add publishing to other package managers
# ...

Expand Down
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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...`);

Expand All @@ -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) {
Expand Down