|
| 1 | +name: Publish JS Client |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + package_path: |
| 7 | + description: Path to directory with package to release |
| 8 | + required: true |
| 9 | + default: "clients/js" |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - clients/js |
| 13 | + - clients/js-legacy |
| 14 | + level: |
| 15 | + description: Version level |
| 16 | + required: true |
| 17 | + default: patch |
| 18 | + type: choice |
| 19 | + options: |
| 20 | + - patch |
| 21 | + - minor |
| 22 | + - major |
| 23 | + - prerelease |
| 24 | + - prepatch |
| 25 | + - preminor |
| 26 | + - premajor |
| 27 | + tag: |
| 28 | + description: NPM Tag (and preid for pre-releases) |
| 29 | + required: true |
| 30 | + type: string |
| 31 | + default: latest |
| 32 | + create_release: |
| 33 | + description: Create a GitHub release |
| 34 | + required: true |
| 35 | + type: boolean |
| 36 | + default: true |
| 37 | + |
| 38 | +jobs: |
| 39 | + test: |
| 40 | + name: Test JS package |
| 41 | + runs-on: ubuntu-latest |
| 42 | + steps: |
| 43 | + - name: Git Checkout |
| 44 | + uses: actions/checkout@v4 |
| 45 | + |
| 46 | + - name: Setup Environment |
| 47 | + uses: ./.github/actions/setup |
| 48 | + with: |
| 49 | + solana: true |
| 50 | + cargo-cache-key: cargo-js-test-publish-${{ inputs.package_path }} |
| 51 | + cargo-cache-fallback-key: cargo-js-test-publish |
| 52 | + |
| 53 | + - name: Format |
| 54 | + run: pnpm zx ./scripts/js/format.mjs "${{ inputs.package_path }}" |
| 55 | + |
| 56 | + - name: Lint |
| 57 | + run: pnpm zx ./scripts/js/lint.mjs "${{ inputs.package_path }}" |
| 58 | + |
| 59 | + - name: Build Record |
| 60 | + run: pnpm programs:build |
| 61 | + |
| 62 | + - name: Test |
| 63 | + run: pnpm zx ./scripts/js/test.mjs "${{ inputs.package_path }}" |
| 64 | + |
| 65 | + publish: |
| 66 | + name: Publish JS package |
| 67 | + runs-on: ubuntu-latest |
| 68 | + needs: test |
| 69 | + permissions: |
| 70 | + contents: write |
| 71 | + steps: |
| 72 | + - name: Git Checkout |
| 73 | + uses: actions/checkout@v4 |
| 74 | + with: |
| 75 | + token: ${{ secrets.ANZA_TEAM_PAT }} |
| 76 | + fetch-depth: 0 # get the whole history for git-cliff |
| 77 | + |
| 78 | + - name: Setup Environment |
| 79 | + uses: ./.github/actions/setup |
| 80 | + |
| 81 | + - name: Ensure SOLANA_NPM_TOKEN variable is set |
| 82 | + env: |
| 83 | + token: ${{ secrets.SOLANA_NPM_TOKEN }} |
| 84 | + if: ${{ env.token == '' }} |
| 85 | + run: | |
| 86 | + echo "The SOLANA_NPM_TOKEN secret variable is not set" |
| 87 | + echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"." |
| 88 | + exit 1 |
| 89 | +
|
| 90 | + - name: Ensure SOLANA_PROGRAM_NPM_TOKEN variable is set |
| 91 | + env: |
| 92 | + token: ${{ secrets.SOLANA_PROGRAM_NPM_TOKEN }} |
| 93 | + if: ${{ env.token == '' }} |
| 94 | + run: | |
| 95 | + echo "The SOLANA_PROGRAM_NPM_TOKEN secret variable is not set" |
| 96 | + echo "Go to \"Settings\" -> \"Secrets and variables\" -> \"Actions\" -> \"New repository secret\"." |
| 97 | + exit 1 |
| 98 | +
|
| 99 | + - name: NPM Authentication |
| 100 | + env: |
| 101 | + SOLANA_NPM_TOKEN: ${{ secrets.SOLANA_NPM_TOKEN }} |
| 102 | + SOLANA_PROGRAM_NPM_TOKEN: ${{ secrets.SOLANA_PROGRAM_NPM_TOKEN }} |
| 103 | + shell: bash |
| 104 | + run: | |
| 105 | + cd "${{ inputs.package_path }}" |
| 106 | + org="$(jq '.name|split("/")|.[0]' package.json)" |
| 107 | + if [[ $org == "\"@solana-program\"" ]] then |
| 108 | + pnpm config set '//registry.npmjs.org/:_authToken' "${SOLANA_PROGRAM_NPM_TOKEN}" |
| 109 | + elif [[ $org == "\"@solana\"" ]] then |
| 110 | + pnpm config set '//registry.npmjs.org/:_authToken' "${SOLANA_NPM_TOKEN}" |
| 111 | + else |
| 112 | + echo "Unknown organization: $org" |
| 113 | + exit 1 |
| 114 | + fi |
| 115 | +
|
| 116 | + - name: Set Git Author |
| 117 | + run: | |
| 118 | + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 119 | + git config --global user.name "github-actions[bot]" |
| 120 | +
|
| 121 | + - name: Publish JS Client |
| 122 | + id: publish |
| 123 | + run: pnpm js:publish "${{ inputs.package_path }}" ${{ inputs.level }} ${{ inputs.tag }} |
| 124 | + |
| 125 | + - name: Push Commit and Tag |
| 126 | + run: git push origin --follow-tags |
| 127 | + |
| 128 | + - name: Generate a changelog |
| 129 | + if: github.event.inputs.create_release == 'true' |
| 130 | + uses: orhun/git-cliff-action@v3 |
| 131 | + with: |
| 132 | + config: "scripts/cliff.toml" |
| 133 | + args: | |
| 134 | + "${{ steps.publish.outputs.old_git_tag }}"..main |
| 135 | + --include-path "${{ inputs.package_path }}/**" |
| 136 | + --github-repo "${{ github.repository }}" |
| 137 | + env: |
| 138 | + OUTPUT: TEMP_CHANGELOG.md |
| 139 | + GITHUB_REPO: ${{ github.repository }} |
| 140 | + |
| 141 | + - name: Create GitHub release |
| 142 | + if: github.event.inputs.create_release == 'true' |
| 143 | + uses: ncipollo/release-action@v1 |
| 144 | + with: |
| 145 | + tag: ${{ steps.publish.outputs.new_git_tag }} |
| 146 | + bodyFile: TEMP_CHANGELOG.md |
0 commit comments