diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b7dac6a..7d96666 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,7 @@ name: CI on: push: branches: [main] + tags: ["v*"] pull_request: permissions: @@ -11,26 +12,100 @@ permissions: jobs: test: runs-on: ubuntu-latest + timeout-minutes: 10 steps: - uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5 with: persist-credentials: false + fetch-depth: 0 - uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2 with: bun-version-file: package.json - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5 with: node-version: 22 + package-manager-cache: false - run: bun install --frozen-lockfile - run: bun run verify - run: test -z "$(git status --porcelain --untracked-files=all -- dist)" - - name: Load the installed package + - name: Validate release tag + if: github.ref_type == 'tag' run: | - artifact="$(bun pm pack --quiet --destination "$RUNNER_TEMP")" + [[ "$GITHUB_REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] + [[ "$GITHUB_REF_NAME" == "v$(node -p "require('./package.json').version")" ]] + git merge-base --is-ancestor HEAD origin/main + - name: Load the installed npm package + run: | + directory="$RUNNER_TEMP/package" + mkdir -p "$directory" + artifact="$(npm pack --ignore-scripts --pack-destination "$directory" --silent)" + (cd "$directory" && sha256sum "$artifact" > SHA256SUMS) cd "$(mktemp -d)" - bun add --ignore-scripts "$artifact" + bun add --ignore-scripts "$directory/$artifact" bun -e 'import { providers } from "@checkfu/integrations/providers"; if (!providers.openai) process.exit(1)' bun -e 'import { connectors } from "@checkfu/integrations/connectors"; if (!connectors.linear) process.exit(1)' node --input-type=module -e 'import { searchToolCatalog } from "@checkfu/integrations/tool-catalog"; if (searchToolCatalog([{ name: "listIssues" }], "list issues").items[0]?.name !== "listIssues") process.exit(1)' node --input-type=module -e 'import { catalogByKind } from "@checkfu/integrations/catalog"; if (!catalogByKind.channel.some(entry => entry.id === "discord")) process.exit(1)' node --input-type=module -e 'import { discordReplyRequest } from "@checkfu/integrations/channels"; if (discordReplyRequest("123", "fixture", "reply").redirect !== "manual") process.exit(1)' + - uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 + with: + name: verified-package + path: ${{ runner.temp }}/package/ + if-no-files-found: error + + publish: + name: Publish verified release + if: github.ref_type == 'tag' && github.event_name == 'push' + needs: test + runs-on: ubuntu-latest + timeout-minutes: 8 + permissions: + contents: write + id-token: write + steps: + - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5 + with: + node-version: 24 + registry-url: https://registry.npmjs.org + package-manager-cache: false + - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4 + with: + name: verified-package + path: package + - name: Publish to npm using trusted publishing + working-directory: package + run: | + sha256sum --check SHA256SUMS + artifact=(checkfu-integrations-*.tgz) + [[ "${#artifact[@]}" == 1 && -f "${artifact[0]}" ]] + version="${GITHUB_REF_NAME#v}" + spec="@checkfu/integrations@$version" + expected="sha512-$(openssl dgst -sha512 -binary "${artifact[0]}" | openssl base64 -A)" + if actual=$(npm view "$spec" dist.integrity); then + if [[ "$actual" != "$expected" ]]; then + # npm can use different gzip encoders. Compare the complete tar contents + # and attach the exact registry archive to the GitHub release. + directory="$(mktemp -d)" + filename="$(npm pack "$spec" --ignore-scripts --pack-destination "$directory" --silent)" + published="$directory/$filename" + integrity="sha512-$(openssl dgst -sha512 -binary "$published" | openssl base64 -A)" + [[ "$integrity" == "$actual" ]] + gzip -dc "${artifact[0]}" > "$directory/verified.tar" + gzip -dc "$published" > "$directory/published.tar" + cmp -s "$directory/verified.tar" "$directory/published.tar" || { + echo "Registry already has different package contents for $spec" >&2 + exit 1 + } + cp "$published" "${artifact[0]}" + sha256sum "${artifact[0]}" > SHA256SUMS + fi + else + npm publish "./${artifact[0]}" --access public --ignore-scripts + fi + - name: Create GitHub release + env: + GH_TOKEN: ${{ github.token }} + run: | + if ! gh release view "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then + gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --verify-tag --generate-notes package/*.tgz package/SHA256SUMS + fi diff --git a/package.json b/package.json index 10a9189..1cb506e 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,10 @@ "engines": { "node": ">=22" }, + "publishConfig": { + "access": "public", + "registry": "https://registry.npmjs.org/" + }, "files": [ "catalog", "dist"