diff --git a/README.md b/README.md index 40fe6c1..7ddef1d 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ steps: uses: pulumi/pulumi-package-publisher@v0.0.6 ``` -Optionally, you may specify language SDKs individually: +Optionally, you may specify language SDKs individually or in a comma separated list: ```yaml steps: @@ -51,19 +51,21 @@ steps: uses: pulumi/pulumi-package-publisher@0058a106b68d8277f17bbea0cd29b2ff6e671adc with: sdk: nodejs - - name: Publish Java SDK + - name: Publish Java and Python SDKs uses: pulumi/pulumi-package-publisher@0058a106b68d8277f17bbea0cd29b2ff6e671adc with: - sdk: java - - name: Publish Python SDK + sdk: java,python + - name: Publish every SDK except .NET uses: pulumi/pulumi-package-publisher@0058a106b68d8277f17bbea0cd29b2ff6e671adc with: - sdk: python + sdk: all,!dotnet ``` Valid inputs to `with.sdk` are: +- `all` - Equivalent to specifying all supported registries: `python,java,nodejs,dotnet` - `python` - Publish to PyPI - `java` - Publish to Maven - `nodejs` - Publish to npm - `dotnet` - Publish to nuget +- `!${LANG}` - To disable any of the above languages. diff --git a/action.yml b/action.yml index 49a84bc..fa54ab9 100644 --- a/action.yml +++ b/action.yml @@ -2,10 +2,36 @@ name: 'Pulumi Package publisher' description: 'A GitHub Action that publishes provider SDKs' inputs: sdk: - description: The name of the language SDK being published + description: | + The name of the language SDK being published. + + To enable a single language, specify that language: + + sdk: nodejs + + To enable multiple languages, specify them: + + sdk: nodejs,python + + To enable all languages (the default), specify 'all': + + sdk: all + + To disable only a single language (but enable all others), use: + + sdk: all,!nodejs + required: false default: 'all' +# The if: statement for the above is: +# +# if: (contains(inputs.sdk, '${LANGUAGE}') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!${LANGUAGE}') +# +# If can be read as: +# +# If (${LANGUAGE} or all (but not !all)) and not !${LANGUAGE} + runs: using: "composite" steps: @@ -29,122 +55,34 @@ runs: repo: pulumi/pulumictl - name: Install Pulumi CLI uses: pulumi/action-install-pulumi-cli@v2 - - name: Setup Node - if: inputs.sdk == 'nodejs' || inputs.sdk == 'all' - uses: actions/setup-node@v3 - with: - node-version: ${{ env.NODEVERSION }} - registry-url: https://registry.npmjs.org - - name: Download nodejs SDK - if: inputs.sdk == 'nodejs' || inputs.sdk == 'all' - uses: actions/download-artifact@v2 - with: - name: nodejs-sdk.tar.gz - path: ${{ github.workspace }}/sdk/ - - name: Uncompress nodejs SDK - if: inputs.sdk == 'nodejs' || inputs.sdk == 'all' - run: tar -zxf ${{ github.workspace }}/sdk/nodejs.tar.gz -C - ${{ github.workspace }}/sdk/nodejs - shell: bash - - name: Run npm whoami - if: inputs.sdk == 'nodejs' || inputs.sdk == 'all' - run: npm whoami - shell: bash - env: - NODE_AUTH_TOKEN: ${{ env.NODE_AUTH_TOKEN }} - - name: Publish Node - if: inputs.sdk == 'nodejs' || inputs.sdk == 'all' - 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 - if: inputs.sdk == 'dotnet' || inputs.sdk == 'all' - uses: actions/setup-dotnet@v3 - with: - dotnet-version: ${{ env.DOTNETVERSION }} - - name: Download dotnet SDK - if: inputs.sdk == 'dotnet' || inputs.sdk == 'all' - uses: actions/download-artifact@v2 - with: - name: dotnet-sdk.tar.gz - path: ${{ github.workspace }}/sdk/ - - name: Uncompress dotnet SDK - if: inputs.sdk == 'dotnet' || inputs.sdk == 'all' - run: tar -zxf ${{ github.workspace }}/sdk/dotnet.tar.gz -C - ${{ github.workspace }}/sdk/dotnet - shell: bash - - name: Publish dotnet SDK - if: inputs.sdk == 'dotnet' || inputs.sdk == 'all' - 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: inputs.sdk == 'python' || inputs.sdk == 'all' - uses: actions/setup-python@v2 - with: - python-version: ${{ env.PYTHONVERSION }} - - name: Download python SDK - if: inputs.sdk == 'python' || inputs.sdk == 'all' - uses: actions/download-artifact@v2 - with: - name: python-sdk.tar.gz - path: ${{ github.workspace }}/sdk/ - - name: Uncompress python SDK - if: inputs.sdk == 'python' || inputs.sdk == 'all' - run: tar -zxf ${{ github.workspace }}/sdk/python.tar.gz -C - ${{ github.workspace }}/sdk/python - shell: bash - - name: Install Twine - if: inputs.sdk == 'python' || inputs.sdk == 'all' - run: python -m pip install pip twine - shell: bash - - name: Publish Python SDK - if: inputs.sdk == 'python' || inputs.sdk == 'all' - 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: inputs.sdk == 'java' || inputs.sdk == 'all' - uses: actions/setup-java@v3 - with: - cache: gradle - distribution: temurin - java-version: ${{ env.JAVAVERSION }} - - name: Setup Gradle - if: inputs.sdk == 'java' || inputs.sdk == 'all' - uses: gradle/gradle-build-action@v2 - with: - gradle-version: "7.6" - - name: Download java SDK - if: inputs.sdk == 'java' || inputs.sdk == 'all' - uses: actions/download-artifact@v2 - with: - name: java-sdk.tar.gz - path: ${{ github.workspace}}/sdk/ - - name: Uncompress java SDK - if: inputs.sdk == 'java' || inputs.sdk == 'all' - run: tar -zxf ${{github.workspace}}/sdk/java.tar.gz -C - ${{github.workspace}}/sdk/java - shell: bash - - name: Set PACKAGE_VERSION to Env - if: inputs.sdk == 'java' || inputs.sdk == 'all' - run: echo "PACKAGE_VERSION=$(pulumictl get version --language generic)" >> - $GITHUB_ENV + + + # `uses:` statements do not support expressions + # (https://github.com/actions/runner/issues/895), so this is invalid: + # + # ${{ github.action_path }}/lang + # + # This is a problem for nested composite actions, which are unable to specify a + # `uses:` relative to the main composite action. + # + # While they need to be static, they do not need to be resolved. We can work around + # the static requirement by specifying a local static path in downstream `uses:`, and + # then moving the desired action to the static path at runtime. + - name: Setup Language Workflows + run: | + mkdir ./.pulumi-package-publish + cp -r ${{ github.action_path }}/lang ./.pulumi-package-publish/lang shell: bash - - name: Publish Java SDK - if: inputs.sdk == 'java' || inputs.sdk == 'all' - continue-on-error: true - uses: gradle/gradle-build-action@9b814496b50909128c6a52622b416c5ffa04db49 - with: - arguments: publishToSonatype closeAndReleaseSonatypeStagingRepository - build-root-directory: ./sdk/java - gradle-version: 7.4.1 + + - name: Nodejs - Publish to NPM + uses: ./.pulumi-package-publish/lang/nodejs + if: (contains(inputs.sdk, 'nodejs') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!nodejs') + - name: .NET - Publish to Nuget + if: (contains(inputs.sdk, 'dotnet') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!dotnet') + uses: ./.pulumi-package-publish/lang/dotnet + - name: Python - Publish to PyPi + if: (contains(inputs.sdk, 'python') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!python') + uses: ./.pulumi-package-publish/lang/python + - name: Java - Publish to Maven + if: (contains(inputs.sdk, 'java') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!java') + uses: ./.pulumi-package-publish/lang/java diff --git a/lang/dotnet/action.yml b/lang/dotnet/action.yml new file mode 100644 index 0000000..78835f9 --- /dev/null +++ b/lang/dotnet/action.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/action.yml b/lang/java/action.yml new file mode 100644 index 0000000..3091573 --- /dev/null +++ b/lang/java/action.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/action.yml b/lang/nodejs/action.yml new file mode 100644 index 0000000..ae0b8f3 --- /dev/null +++ b/lang/nodejs/action.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/action.yml b/lang/python/action.yml new file mode 100644 index 0000000..f8369a7 --- /dev/null +++ b/lang/python/action.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