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

sdk include/exclude logic #21

Merged
merged 8 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,29 @@ steps:
uses: pulumi/[email protected]
```

Optionally, you may specify language SDKs individually:
Optionally, you may specify language SDKs individually or in a comma separated list:

```yaml
steps:
- name: Publish nodejs SDK
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
Copy link
Contributor

Choose a reason for hiding this comment

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

non-blocking: probably will want to remove the explicit version tagging here and elsewhere, or use @main

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.
68 changes: 47 additions & 21 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -30,77 +56,77 @@ runs:
- name: Install Pulumi CLI
uses: pulumi/action-install-pulumi-cli@v2
- name: Setup Node
if: inputs.sdk == 'nodejs' || inputs.sdk == 'all'
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: inputs.sdk == 'nodejs' || inputs.sdk == 'all'
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: inputs.sdk == 'nodejs' || inputs.sdk == 'all'
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: inputs.sdk == 'nodejs' || inputs.sdk == 'all'
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: inputs.sdk == 'nodejs' || inputs.sdk == 'all'
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
if: inputs.sdk == 'dotnet' || inputs.sdk == 'all'
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: inputs.sdk == 'dotnet' || inputs.sdk == 'all'
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: inputs.sdk == 'dotnet' || inputs.sdk == 'all'
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: inputs.sdk == 'dotnet' || inputs.sdk == 'all'
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: inputs.sdk == 'python' || inputs.sdk == 'all'
if: (contains(inputs.sdk, 'python') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!python')
Copy link
Member

Choose a reason for hiding this comment

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

🤯

This is good to go but let's not make too many more changes like this on top of this one or else we'll end up needing a SAT solver to understand what's going on. I fully appreciate that GHA have limited abstraction capacity so this may be needed...

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need a SAT solver... but I did build this to verify the logic:

def contains(haystack: str, needle: str) -> bool:
    return needle in haystack

class input:
    def __init__(self, sdk):
        self.sdk = sdk

def check(query: str, sdk: str) -> bool:
    inputs = input(sdk)
    return eval(query.replace("||", "or").replace("&&", "and").replace(" !", " not "))

check("(contains(inputs.sdk, 'nodejs') || (contains(inputs.sdk, 'all') && !contains(inputs.sdk, '!all'))) && !contains(inputs.sdk, '!nodejs')", "!all")

We've shot ourselves in the foot several times with arrays vs strings through composite actions. It seems like everything is stringly typed given enough transformations. I don't think we will need to make any more changes here. 🤞

I might be able to refactor so the check only needs to show up once per language.

uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHONVERSION }}
- name: Download python SDK
if: inputs.sdk == 'python' || inputs.sdk == 'all'
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: inputs.sdk == 'python' || inputs.sdk == 'all'
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: inputs.sdk == 'python' || inputs.sdk == 'all'
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: inputs.sdk == 'python' || inputs.sdk == 'all'
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";
Expand All @@ -113,35 +139,35 @@ runs:
--verbose
shell: bash
- name: Setup Java
if: inputs.sdk == 'java' || inputs.sdk == 'all'
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
if: inputs.sdk == 'java' || inputs.sdk == 'all'
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: inputs.sdk == 'java' || inputs.sdk == 'all'
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: inputs.sdk == 'java' || inputs.sdk == 'all'
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: inputs.sdk == 'java' || inputs.sdk == 'all'
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: inputs.sdk == 'java' || inputs.sdk == 'all'
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:
Expand Down