diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..089301b --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,22 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu +{ + "name": "Ubuntu", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/base:jammy", + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/devcontainers-contrib/features/act:1": {}, + "ghcr.io/devcontainers-contrib/features/actionlint:1": {} + } + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "uname -a", + // Configure tool-specific properties. + // "customizations": {}, + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..f33a02c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for more information: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +# https://containers.dev/guide/dependabot + +version: 2 +updates: + - package-ecosystem: "devcontainers" + directory: "/" + schedule: + interval: weekly diff --git a/.github/workflows/test-release.yml b/.github/workflows/test-release.yml new file mode 100644 index 0000000..b1a1168 --- /dev/null +++ b/.github/workflows/test-release.yml @@ -0,0 +1,123 @@ +name: Test & Release + +on: + workflow_dispatch: + push: + +# env: +# FIELD_ID: PVTF_lADOCOJGKs4AX9CyzgPUCoI +# SELECT_FIELD_ID: PVTSSF_lADOCOJGKs4AX9CyzgPUCro +# SELECT_OPTION_ID: 4b83566e +# SELECT_COMPLEX_FIELD_ID: PVTSSF_lADOCOJGKs4AX9CyzgVbXGE +# SELECT_COMPLEX_OPTION_ID: 0a479792 + +permissions: + contents: write + issues: write + pull-requests: write + +jobs: + test: + name: Test + runs-on: ubuntu-latest + strategy: + matrix: + include: + - test-name: "Get field id" + field-name: "Test Field" + selection-option-name: "" + expected-field-id: PVTF_lADOCOJGKs4AX9CyzgPUCoI + expected-secection-option-id: "null" + - test-name: "Get select option id" + field-name: "Test select field" + selection-option-name: "Option1" + expected-field-id: PVTSSF_lADOCOJGKs4AX9CyzgPUCro + expected-secection-option-id: 4b83566e + - test-name: "Get Complex select option id" + field-name: "Test complex select field" + selection-option-name: "Complex Option 1" + expected-field-id: PVTSSF_lADOCOJGKs4AX9CyzgVbXGE + expected-secection-option-id: 0a479792 + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + show-progress: false + - uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ vars.TESTING_APP_ID }} + private-key: ${{ secrets.TESTING_APP_KEY }} + - name: Exec + id: get-field-id + uses: ./ + with: + token: ${{ steps.app-token.outputs.token }} + project-number: 1 + project-owner: infinite-automations + field-name: ${{ matrix.field-name }} + select-option-name: ${{ matrix.selection-option-name }} + - name: Test field ID + uses: nick-fields/assert-action@v2 + with: + expected: ${{ matrix.expected-field-id }} + actual: ${{ steps.get-field-id.outputs.field-id }} + comparison: exact + - name: Test select option ID + uses: nick-fields/assert-action@v2 + with: + expected: ${{ matrix.expected-secection-option-id }} + actual: ${{ steps.get-field-id.outputs.select-option-id }} + comparison: exact + + # - name: Get select option id + # id: get-select-option-id + # uses: ./ + # with: + # token: ${{ steps.app-token.outputs.token }} + # project-number: 1 + # project-owner: infinite-automations + # field-name: Test select field + # select-option-name: Option1 + # - name: Test Get select option id + # uses: nick-fields/assert-action@v2 + # with: + # expected: ${{ env.SELECT_OPTION_ID }} + # actual: ${{ steps.get-select-option-id.outputs.select-option-id }} + # comparison: exact + # - name: Get Complex select option id + # id: get-complex-select-option-id + # uses: ./ + # with: + # token: ${{ steps.app-token.outputs.token }} + # project-number: 1 + # project-owner: infinite-automations + # field-name: Test complex select field + # select-option-name: Complex Option 1 + # - name: Test Get complex select option id + # uses: nick-fields/assert-action@v2 + # with: + # expected: ${{ env.SELECT_COMPLEX_OPTION_ID }} + # actual: ${{ steps.get-complex-select-option-id.outputs.select-option-id }} + # comparison: exact + + release: + name: Release + needs: + - test + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Install Semantic Release Plugins + run: | + npm install semantic-release-replace-plugin -D + npm install --save-dev semantic-release-major-tag + - name: Semantic Release + uses: cycjimmy/semantic-release-action@v4 + with: + dry_run: ${{ github.event_name == 'pull_request' }} + ci: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 63ab245..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: Test - -on: - workflow_dispatch: - push: - -env: - FIELD_ID: PVTF_lADOCOJGKs4AX9CyzgPUCoI - SELECT_FIELD_ID: PVTSSF_lADOCOJGKs4AX9CyzgPUCro - SELECT_OPTION_ID: 4b83566e - SELECT_COMPLEX_FIELD_ID: PVTSSF_lADOCOJGKs4AX9CyzgVbXGE - SELECT_COMPLEX_OPTION_ID: 0a479792 - -jobs: - test: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - show-progress: false - - name: Get field id - id: get-field-id - uses: ./ - with: - token: ${{ secrets.PROJECT_TOKEN }} - project-number: 1 - project-owner: infinite-automations - field-name: Test Field - - name: Test Get field id - uses: nick-fields/assert-action@v2 - with: - expected: ${{ env.FIELD_ID }} - actual: ${{ steps.get-field-id.outputs.field-id }} - comparison: exact - - name: Get select option id - id: get-select-option-id - uses: ./ - with: - token: ${{ secrets.PROJECT_TOKEN }} - project-number: 1 - project-owner: infinite-automations - field-name: Test select field - select-option-name: Option1 - - name: Test Get select option id - uses: nick-fields/assert-action@v2 - with: - expected: ${{ env.SELECT_OPTION_ID }} - actual: ${{ steps.get-select-option-id.outputs.select-option-id }} - comparison: exact - - name: Get Complex select option id - id: get-complex-select-option-id - uses: ./ - with: - token: ${{ secrets.PROJECT_TOKEN }} - project-number: 1 - project-owner: infinite-automations - field-name: Test complex select field - select-option-name: Complex Option 1 - - name: Test Get complex select option id - uses: nick-fields/assert-action@v2 - with: - expected: ${{ env.SELECT_COMPLEX_OPTION_ID }} - actual: ${{ steps.get-complex-select-option-id.outputs.select-option-id }} - comparison: exact - diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..2cb97c2 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,59 @@ +{ + "branches": [ + "main" + ], + "tagFormat": "v${version}", + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + "@semantic-release/github", + [ + "semantic-release-major-tag", + { + "customTags": [ + "v${major}", + "v${major}.${minor}" + ] + } + ], + [ + "semantic-release-replace-plugin", + { + "replacements": [ + { + "files": [ + "README.md" + ], + "from": "uses: infinite-automations/gh-projects-field-ids@.*", + "to": "uses: infinite-automations/gh-projects-field-ids@v${nextRelease.version}", + "results": [ + { + "file": "README.md", + "hasChanged": true, + "numMatches": 1, + "numReplacements": 1 + } + ], + "countMatches": true + } + ] + } + ], + [ + "@semantic-release/changelog", + { + "changelogFile": "CHANGELOG.md" + } + ], + [ + "@semantic-release/git", + { + "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}", + "assets": [ + "CHANGELOG.md", + "README.md" + ] + } + ] + ] +} \ No newline at end of file diff --git a/action.yml b/action.yml index 6b89ad1..0fba406 100644 --- a/action.yml +++ b/action.yml @@ -24,29 +24,49 @@ inputs: outputs: field-id: description: "The id for the given field" - value: ${{ steps.get-field-id.outputs.id }} + value: ${{ steps.get-ids.outputs.field-id }} select-option-id: description: "The id for the given select option" - value: ${{ steps.get-select-option-id.outputs.id }} + value: ${{ steps.get-ids.outputs.select-option-id }} runs: using: "composite" steps: - name: Get field id - id: get-field-id + id: get-ids if: ${{ inputs.field-name }} shell: bash env: GH_TOKEN: ${{ inputs.token }} run: | - field_id=$(gh project field-list ${{ inputs.project-number }} --owner "${{ inputs.project-owner }}" --format json | jq -r --arg fieldName "${{ inputs.field-name }}" '.fields[] | select(.name==$fieldName) .id') - echo "id=$field_id" >> "$GITHUB_OUTPUT" - - name: Get select option id - id: get-select-option-id - if: ${{ inputs.select-option-name }} - shell: bash - env: - GH_TOKEN: ${{ inputs.token }} - run: | - field_id=$(gh project field-list ${{ inputs.project-number }} --owner "${{ inputs.project-owner }}" --format json | jq -r --arg fieldName "${{ inputs.field-name }}" --arg selectOptionName "${{ inputs.select-option-name }}" '.fields[] | select(.name==$fieldName) .options[] | select(.name==$selectOptionName) .id') - echo "id=$field_id" >> "$GITHUB_OUTPUT" + JSON=$(\ + gh project field-list ${{ inputs.project-number }} \ + --owner "${{ inputs.project-owner }}" \ + --format json \ + ) + echo JSON: + echo $JSON + echo + + FIELD_ID=$(\ + echo "$JSON" \ + | jq -r \ + --arg fieldName "${{ inputs.field-name }}" \ + '.fields[] | select(.name=="$fieldName") .id' \ + ) + echo FIELD_ID: + echo $FIELD_ID + echo + echo "field-id=$FIELD_ID" >> "$GITHUB_OUTPUT" + + SELECTION_OPTION_ID=$(\ + echo "$JSON" \ + | jq -r \ + --arg fieldName "${{ inputs.field-name }}" \ + --arg selectOptionName "${{ inputs.select-option-name }}" \ + '.fields[] | select(.name=="$fieldName") .options[] | select(.name=="$selectOptionName") .id' \ + ) + echo SELECTION_OPTION_ID: + echo $SELECTION_OPTION_ID + echo + echo "select-option-id=$SELECTION_OPTION_ID" >> "$GITHUB_OUTPUT"