|
| 1 | +name: ci-release-js |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + tag: |
| 7 | + type: string |
| 8 | + description: 'Exact git tag to release (omit to use HEAD)' |
| 9 | + required: false |
| 10 | + workflow_dispatch: |
| 11 | + inputs: |
| 12 | + tag: |
| 13 | + description: 'Git tag to release (leave blank for HEAD)' |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + prerelease_name: |
| 17 | + description: 'Suffix for a manual pre-release (blank = full release)' |
| 18 | + required: false |
| 19 | + type: string |
| 20 | + default: '' |
| 21 | + skip_publish: |
| 22 | + description: 'Skip publishing to npm' |
| 23 | + required: false |
| 24 | + type: boolean |
| 25 | + default: true |
| 26 | + |
| 27 | +jobs: |
| 28 | + create-release: |
| 29 | + name: Create release for TS library |
| 30 | + runs-on: ubuntu-latest |
| 31 | + permissions: |
| 32 | + contents: write |
| 33 | + id-token: write |
| 34 | + defaults: |
| 35 | + run: |
| 36 | + working-directory: ./proof_verifier_js/ts |
| 37 | + |
| 38 | + env: |
| 39 | + COMPILE_ARTIFACTS: 'false' |
| 40 | + |
| 41 | + steps: |
| 42 | + - name: Checkout sources |
| 43 | + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
| 44 | + with: |
| 45 | + fetch-depth: 0 |
| 46 | + ref: ${{ inputs.tag || '' }} |
| 47 | + |
| 48 | + - name: Determine tag |
| 49 | + id: tag |
| 50 | + run: | |
| 51 | + TAG_INPUT="${{ inputs.tag }}" |
| 52 | +
|
| 53 | + # Check if the tag input is provided |
| 54 | + if [ -n "$TAG_INPUT" ]; then |
| 55 | + # Sanitize the input - request by security team |
| 56 | + # Replace any character that is NOT |
| 57 | + # alphanumeric, a hyphen, an underscore, or a period with nothing. |
| 58 | + # This prevents unexpected shell chars (like ;, $, |, etc.) |
| 59 | + # from being executed. |
| 60 | + SANITIZED_TAG=$(echo "$TAG_INPUT" | tr -cd '[:alnum:]._-') |
| 61 | +
|
| 62 | + # Use the sanitized tag |
| 63 | + echo "value=$SANITIZED_TAG" >> "$GITHUB_OUTPUT" |
| 64 | +
|
| 65 | + if [ "$TAG_INPUT" != "$SANITIZED_TAG" ]; then |
| 66 | + echo "Warning: Input tag was sanitized from '$TAG_INPUT' to '$SANITIZED_TAG'" |
| 67 | + fi |
| 68 | +
|
| 69 | + else |
| 70 | + # Fallback to commit short SHA if no tag is provided |
| 71 | + echo "value=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT" |
| 72 | + fi |
| 73 | +
|
| 74 | + - name: Update release-please release artifacts |
| 75 | + if: ${{ inputs.tag != '' }} |
| 76 | + uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0 |
| 77 | + with: |
| 78 | + tag_name: ${{ inputs.tag }} |
| 79 | + |
| 80 | + - name: Publish release |
| 81 | + if: ${{ inputs.prerelease_name != '' }} |
| 82 | + uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0 |
| 83 | + with: |
| 84 | + tag_name: ${{ steps.tag.outputs.value }} |
| 85 | + name: ethproofs-airbender-verifier ${{ steps.tag.outputs.value }}${{ inputs.prerelease_name && format(' {0}', inputs.prerelease_name) || '' }} |
| 86 | + target_commitish: ${{ github.sha }} |
| 87 | + prerelease: ${{ inputs.prerelease_name != '' }} |
| 88 | + |
| 89 | + # Trigger package publishing to npm registry |
| 90 | + publish: |
| 91 | + name: Publish TS library to npm |
| 92 | + runs-on: ubuntu-latest |
| 93 | + if: ${{ inputs.skip_publish != 'true' }} |
| 94 | + permissions: |
| 95 | + contents: read |
| 96 | + id-token: write # Required for npm OIDC trusted publishing |
| 97 | + defaults: |
| 98 | + run: |
| 99 | + working-directory: ./proof_verifier_js/ts |
| 100 | + |
| 101 | + steps: |
| 102 | + - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 |
| 103 | + |
| 104 | + - name: Install Rust toolchain |
| 105 | + uses: moonrepo/setup-rust@ede6de059f8046a5e236c94046823e2af11ca670 # v1.2.2 |
| 106 | + with: |
| 107 | + inherit-toolchain: true |
| 108 | + |
| 109 | + - uses: taiki-e/install-action@3522286d40783523f9c7880e33f785905b4c20d0 # v2.66.1 |
| 110 | + with: |
| 111 | + tool: wasm-pack |
| 112 | + |
| 113 | + |
| 114 | + - uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 |
| 115 | + with: |
| 116 | + node-version: 22.x |
| 117 | + registry-url: 'https://registry.npmjs.org' |
| 118 | + |
| 119 | + - uses: mskelton/setup-yarn@8d0bc12bc7f72a9acfc32019da0381dfcb481df0 # v3.0.0 |
| 120 | + |
| 121 | + - name: Upgrade npm for OIDC support |
| 122 | + run: npm install -g npm@11.7.0 |
| 123 | + |
| 124 | + - name: Install deps |
| 125 | + run: yarn install |
| 126 | + |
| 127 | + - name: Build |
| 128 | + run: yarn build |
| 129 | + |
| 130 | + - name: Publish to npm |
| 131 | + run: npm publish --access public --tag latest --provenance |
0 commit comments