Skip to content

Commit

Permalink
feat(dotnet): publish to public nuget registry option
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbriere1 committed Nov 14, 2024
1 parent e67a05d commit 908bf1a
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/dotnet-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ on:
required: true
type: string
description: "The package version to use"
publish_to_public_registry:
required: false
type: boolean
description: "Whether to publish to the public registry"
default: true

jobs:
publish:
Expand All @@ -20,6 +25,8 @@ jobs:
packages: read
environment: main
env:
VAULT_URL: ${{ vars.VAULT_URL }}
VAULT_GITHUB_ACTIONS_ROLE: ${{ vars.VAULT_GITHUB_ACTIONS_ROLE }}
AWS_ACCOUNT_ID: ${{ inputs.AWS_ACCOUNT_ID || vars.AWS_ACCOUNT_ID }}
AWS_REGION: ${{ inputs.AWS_REGION || vars.AWS_REGION }}
CODEARTIFACT_DOMAIN: smartway
Expand All @@ -40,6 +47,32 @@ jobs:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/github_oidc

- name: Tailscale
if: inputs.publish_to_public_registry
uses: tailscale/github-action@v2
with:
oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
tags: tag:ci
version: ${{ vars.TAILSCALE_VERSION }}

- name: Import Secrets
if: inputs.publish_to_public_registry
uses: Wandalen/wretry.action@v3
id: secrets
with:
action: hashicorp/vault-action@v3
attempt_limit: 5
attempt_delay: 150
with: |
url: ${{ env.VAULT_URL }}
role: ${{ env.VAULT_GITHUB_ACTIONS_ROLE }}
method: jwt
path: "github-actions"
exportToken: true
secrets: |
secret/data/github-actions-common/nuget-registry api-key | NUGET_PUBLIC_API_KEY;
- name: Login to CodeArtifact
run: "aws codeartifact login --tool dotnet --repository ${CODEARTIFACT_REPOSITORY} --domain ${CODEARTIFACT_DOMAIN} --domain-owner ${AWS_ACCOUNT_ID} --region ${AWS_REGION}"

Expand All @@ -57,3 +90,11 @@ jobs:
dotnet nuget push ${{ inputs.package_to_publish }}.${{ inputs.package_version }}/${{ inputs.package_to_publish }}.${{ inputs.package_version }}.nupkg
--source https://${{ env.CODEARTIFACT_DOMAIN }}-${{ env.AWS_ACCOUNT_ID }}.d.codeartifact.${{ env.AWS_REGION }}.amazonaws.com/nuget/${{ env.CODEARTIFACT_REPOSITORY }}/v3/index.json
--skip-duplicate
- name: Publish package to Public Registry
if: inputs.publish_to_public_registry
run: >-
dotnet nuget push ${{ inputs.package_to_publish }}.${{ inputs.package_version }}/${{ inputs.package_to_publish }}.${{ inputs.package_version }}.nupkg
--source https://api.nuget.org/v3/index.json
--api-key ${{ fromJSON( steps.secrets.outputs.outputs ).NUGET_PUBLIC_API_KEY }}
--skip-duplicate

0 comments on commit 908bf1a

Please sign in to comment.