From a7c541c88850c23a58406e881982801469f69cd5 Mon Sep 17 00:00:00 2001 From: Ian Wahbe Date: Wed, 27 Dec 2023 17:36:06 +0100 Subject: [PATCH] Refactor out each language to it's own composite action This makes it much easier to read the composite action, and reduces the need to include the (increasingly complicated) `if:` check in each step. I'm not 100% sure this will work, and I'm not aware of a way to test. I'm going to push this, then check that it works as expected. --- action.yml | 123 ++++-------------------------------------------- lang/dotnet.yml | 23 +++++++++ lang/java.yml | 36 ++++++++++++++ lang/nodejs.yml | 30 ++++++++++++ lang/python.yml | 34 +++++++++++++ 5 files changed, 131 insertions(+), 115 deletions(-) create mode 100644 lang/dotnet.yml create mode 100644 lang/java.yml create mode 100644 lang/nodejs.yml create mode 100644 lang/python.yml diff --git a/action.yml b/action.yml index dd48aba..943626e 100644 --- a/action.yml +++ b/action.yml @@ -55,122 +55,15 @@ runs: repo: pulumi/pulumictl - name: Install Pulumi CLI uses: pulumi/action-install-pulumi-cli@v2 - - name: Setup Node + - name: Nodejs - Publish to NPM + uses: ./lang/nodejs.yml if: (contains(inputs.sdk, 'nodejs') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!nodejs') - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODEVERSION }} - registry-url: https://registry.npmjs.org - - name: Download nodejs SDK - if: (contains(inputs.sdk, 'nodejs') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!nodejs') - uses: actions/download-artifact@v2 - with: - name: nodejs-sdk.tar.gz - path: ${{ github.workspace }}/sdk/ - - name: Uncompress nodejs SDK - if: (contains(inputs.sdk, 'nodejs') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!nodejs') - run: tar -zxf ${{ github.workspace }}/sdk/nodejs.tar.gz -C - ${{ github.workspace }}/sdk/nodejs - shell: bash - - name: Run npm whoami - if: (contains(inputs.sdk, 'nodejs') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!nodejs') - run: npm whoami - shell: bash - env: - NODE_AUTH_TOKEN: ${{ env.NODE_AUTH_TOKEN }} - - name: Publish Node - if: (contains(inputs.sdk, 'nodejs') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!nodejs') - run: pulumi package publish-sdk nodejs --path ${{ github.workspace }}/sdk/nodejs/bin - shell: bash - env: - NODE_AUTH_TOKEN: ${{ env.NODE_AUTH_TOKEN }} - - name: Setup DotNet + - name: .NET - Publish to Nuget if: (contains(inputs.sdk, 'dotnet') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!dotnet') - uses: actions/setup-dotnet@v3 - with: - dotnet-version: ${{ env.DOTNETVERSION }} - - name: Download dotnet SDK - if: (contains(inputs.sdk, 'dotnet') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!dotnet') - uses: actions/download-artifact@v2 - with: - name: dotnet-sdk.tar.gz - path: ${{ github.workspace }}/sdk/ - - name: Uncompress dotnet SDK - if: (contains(inputs.sdk, 'dotnet') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!dotnet') - run: tar -zxf ${{ github.workspace }}/sdk/dotnet.tar.gz -C - ${{ github.workspace }}/sdk/dotnet - shell: bash - - name: Publish dotnet SDK - if: (contains(inputs.sdk, 'dotnet') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!dotnet') - run: find "${{ github.workspace }}/sdk/dotnet/bin/Debug/" -name 'Pulumi.*.nupkg' - -exec dotnet nuget push -k "${NUGET_PUBLISH_KEY}" -s https://api.nuget.org/v3/index.json {} \; - shell: bash - - name: Setup Python - if: (contains(inputs.sdk, 'python') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!python') - uses: actions/setup-python@v2 - with: - python-version: ${{ env.PYTHONVERSION }} - - name: Download python SDK + uses: ./lang/dotnet.yml + - name: Python - Publish to PyPi if: (contains(inputs.sdk, 'python') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!python') - uses: actions/download-artifact@v2 - with: - name: python-sdk.tar.gz - path: ${{ github.workspace }}/sdk/ - - name: Uncompress python SDK - if: (contains(inputs.sdk, 'python') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!python') - run: tar -zxf ${{ github.workspace }}/sdk/python.tar.gz -C - ${{ github.workspace }}/sdk/python - shell: bash - - name: Install Twine - if: (contains(inputs.sdk, 'python') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!python') - run: python -m pip install pip twine - shell: bash - - name: Publish Python SDK - if: (contains(inputs.sdk, 'python') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!python') - run: if [ -n "${PYPI_USERNAME}" ] ; - then PYPI_PUBLISH_USERNAME=${PYPI_USERNAME}; - else PYPI_PUBLISH_USERNAME="pulumi"; - fi && - echo "Publishing Pip package to pypi as ${PYPI_PUBLISH_USERNAME}:" && - twine upload - -u "${PYPI_PUBLISH_USERNAME}" -p "${PYPI_PASSWORD}" - "${{ github.workspace }}/sdk/python/bin/dist/*" - --skip-existing - --verbose - shell: bash - - name: Setup Java - if: (contains(inputs.sdk, 'java') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!java') - uses: actions/setup-java@v3 - with: - cache: gradle - distribution: temurin - java-version: ${{ env.JAVAVERSION }} - - name: Setup Gradle + uses: ./lang/python.yml + - name: Java - Publish to Maven if: (contains(inputs.sdk, 'java') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!java') - uses: gradle/gradle-build-action@v2 - with: - gradle-version: "7.6" - - name: Download java SDK - if: (contains(inputs.sdk, 'java') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!java') - uses: actions/download-artifact@v2 - with: - name: java-sdk.tar.gz - path: ${{ github.workspace}}/sdk/ - - name: Uncompress java SDK - if: (contains(inputs.sdk, 'java') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!java') - run: tar -zxf ${{github.workspace}}/sdk/java.tar.gz -C - ${{github.workspace}}/sdk/java - shell: bash - - name: Set PACKAGE_VERSION to Env - if: (contains(inputs.sdk, 'java') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!java') - run: echo "PACKAGE_VERSION=$(pulumictl get version --language generic)" >> - $GITHUB_ENV - shell: bash - - name: Publish Java SDK - if: (contains(inputs.sdk, 'java') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!java') - continue-on-error: true - uses: gradle/gradle-build-action@9b814496b50909128c6a52622b416c5ffa04db49 - with: - arguments: publishToSonatype closeAndReleaseSonatypeStagingRepository - build-root-directory: ./sdk/java - gradle-version: 7.4.1 + uses: ./lang/java.yml diff --git a/lang/dotnet.yml b/lang/dotnet.yml new file mode 100644 index 0000000..78835f9 --- /dev/null +++ b/lang/dotnet.yml @@ -0,0 +1,23 @@ +name: 'Publish to Nuget' +description: 'A subcomponent of pulumi-package-publish' + +runs: + using: "composite" + steps: + - name: Setup DotNet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: ${{ env.DOTNETVERSION }} + - name: Download dotnet SDK + uses: actions/download-artifact@v2 + with: + name: dotnet-sdk.tar.gz + path: ${{ github.workspace }}/sdk/ + - name: Uncompress dotnet SDK + run: tar -zxf ${{ github.workspace }}/sdk/dotnet.tar.gz -C + ${{ github.workspace }}/sdk/dotnet + shell: bash + - name: Publish dotnet SDK + run: find "${{ github.workspace }}/sdk/dotnet/bin/Debug/" -name 'Pulumi.*.nupkg' + -exec dotnet nuget push -k "${NUGET_PUBLISH_KEY}" -s https://api.nuget.org/v3/index.json {} \; + shell: bash diff --git a/lang/java.yml b/lang/java.yml new file mode 100644 index 0000000..3091573 --- /dev/null +++ b/lang/java.yml @@ -0,0 +1,36 @@ +name: 'Publish to Maven' +description: 'A subcomponent of pulumi-package-publish' + +runs: + using: "composite" + steps: + - name: Setup Java + uses: actions/setup-java@v3 + with: + cache: gradle + distribution: temurin + java-version: ${{ env.JAVAVERSION }} + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + with: + gradle-version: "7.6" + - name: Download java SDK + uses: actions/download-artifact@v2 + with: + name: java-sdk.tar.gz + path: ${{ github.workspace}}/sdk/ + - name: Uncompress java SDK + run: tar -zxf ${{github.workspace}}/sdk/java.tar.gz -C + ${{github.workspace}}/sdk/java + shell: bash + - name: Set PACKAGE_VERSION to Env + run: echo "PACKAGE_VERSION=$(pulumictl get version --language generic)" >> + $GITHUB_ENV + shell: bash + - name: Publish Java SDK + continue-on-error: true + uses: gradle/gradle-build-action@9b814496b50909128c6a52622b416c5ffa04db49 + with: + arguments: publishToSonatype closeAndReleaseSonatypeStagingRepository + build-root-directory: ./sdk/java + gradle-version: 7.4.1 diff --git a/lang/nodejs.yml b/lang/nodejs.yml new file mode 100644 index 0000000..ae0b8f3 --- /dev/null +++ b/lang/nodejs.yml @@ -0,0 +1,30 @@ +name: 'Publish to NPM' +description: 'A subcomponent of pulumi-package-publish' + +runs: + using: "composite" + steps: + - name: Setup Node + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODEVERSION }} + registry-url: https://registry.npmjs.org + - name: Download nodejs SDK + uses: actions/download-artifact@v2 + with: + name: nodejs-sdk.tar.gz + path: ${{ github.workspace }}/sdk/ + - name: Uncompress nodejs SDK + run: tar -zxf ${{ github.workspace }}/sdk/nodejs.tar.gz -C + ${{ github.workspace }}/sdk/nodejs + shell: bash + - name: Run npm whoami + run: npm whoami + shell: bash + env: + NODE_AUTH_TOKEN: ${{ env.NODE_AUTH_TOKEN }} + - name: Publish Node + run: pulumi package publish-sdk nodejs --path ${{ github.workspace }}/sdk/nodejs/bin + shell: bash + env: + NODE_AUTH_TOKEN: ${{ env.NODE_AUTH_TOKEN }} diff --git a/lang/python.yml b/lang/python.yml new file mode 100644 index 0000000..f8369a7 --- /dev/null +++ b/lang/python.yml @@ -0,0 +1,34 @@ +name: 'Publish to PyPi' +description: 'A subcomponent of pulumi-package-publish' + +runs: + using: "composite" + steps: + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: ${{ env.PYTHONVERSION }} + - name: Download python SDK + uses: actions/download-artifact@v2 + with: + name: python-sdk.tar.gz + path: ${{ github.workspace }}/sdk/ + - name: Uncompress python SDK + run: tar -zxf ${{ github.workspace }}/sdk/python.tar.gz -C + ${{ github.workspace }}/sdk/python + shell: bash + - name: Install Twine + run: python -m pip install pip twine + shell: bash + - name: Publish Python SDK + run: if [ -n "${PYPI_USERNAME}" ] ; + then PYPI_PUBLISH_USERNAME=${PYPI_USERNAME}; + else PYPI_PUBLISH_USERNAME="pulumi"; + fi && + echo "Publishing Pip package to pypi as ${PYPI_PUBLISH_USERNAME}:" && + twine upload + -u "${PYPI_PUBLISH_USERNAME}" -p "${PYPI_PASSWORD}" + "${{ github.workspace }}/sdk/python/bin/dist/*" + --skip-existing + --verbose + shell: bash