Standardize Google integration ids to google_* (v0.10.0) #211
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish to npm | |
| on: | |
| workflow_call: | |
| inputs: | |
| version: | |
| required: true | |
| type: string | |
| description: "The version to publish" | |
| npm-tag: | |
| required: false | |
| type: string | |
| default: "latest" | |
| description: "The npm dist-tag (e.g., 'latest' or 'dev')" | |
| is-prerelease: | |
| required: false | |
| type: boolean | |
| default: false | |
| description: "Whether this is a prerelease" | |
| release-name-prefix: | |
| required: false | |
| type: string | |
| default: "Release" | |
| description: "Prefix for the release name" | |
| secrets: | |
| DISCORD_WEBHOOK_URL: | |
| required: false | |
| description: "Discord webhook URL for notifications" | |
| push: | |
| branches: | |
| - main | |
| paths-ignore: | |
| - "**.md" | |
| - "docs/**" | |
| - "examples/**" | |
| - ".github/**" | |
| - "!.github/workflows/publish.yml" | |
| permissions: | |
| contents: write # Required to create releases and tags | |
| id-token: write # Required for NPM Trusted Publishing (OIDC) | |
| jobs: | |
| check-version: | |
| # Also run for workflow_call so reusable callers satisfy downstream needs. | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version-changed: ${{ steps.check.outputs.changed }} | |
| version: ${{ steps.package.outputs.version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Get current version | |
| id: package | |
| run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
| - name: Get previous version | |
| id: previous | |
| run: | | |
| git checkout HEAD^ -- package.json | |
| echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT | |
| git checkout HEAD -- package.json | |
| - name: Check if version changed | |
| id: check | |
| run: | | |
| CURRENT_VERSION="${{ steps.package.outputs.version }}" | |
| PREVIOUS_VERSION="${{ steps.previous.outputs.version }}" | |
| echo "Current version: $CURRENT_VERSION" | |
| echo "Previous version: $PREVIOUS_VERSION" | |
| if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then | |
| echo "changed=true" >> $GITHUB_OUTPUT | |
| echo "✅ Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION" | |
| else | |
| echo "changed=false" >> $GITHUB_OUTPUT | |
| echo "❌ Version not changed, skipping publish" | |
| fi | |
| test: | |
| # Always evaluate, but check-version might be skipped for workflow_call | |
| if: | | |
| always() && | |
| (inputs.version != '' || | |
| (needs.check-version.result == 'success' && needs.check-version.outputs.version-changed == 'true')) | |
| needs: check-version | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: 1.2.21 | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Type check | |
| run: bun run type-check | |
| - name: Run tests | |
| run: bun run test | |
| - name: Build | |
| run: bun run build | |
| publish: | |
| needs: [check-version, test] | |
| # Run after tests pass | |
| if: | | |
| always() && | |
| needs.test.result == 'success' && | |
| (inputs.version != '' || | |
| (needs.check-version.result == 'success' && needs.check-version.outputs.version-changed == 'true')) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Bun | |
| uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: 1.2.21 | |
| - name: Install dependencies | |
| run: bun install | |
| - name: Build | |
| run: bun run build | |
| - name: Determine version to publish | |
| id: version | |
| run: | | |
| VERSION="${{ inputs.version || needs.check-version.outputs.version }}" | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "Publishing version: $VERSION" | |
| - name: Determine npm tag | |
| id: npm-tag | |
| run: | | |
| NPM_TAG="${{ inputs.npm-tag || 'latest' }}" | |
| echo "tag=$NPM_TAG" >> $GITHUB_OUTPUT | |
| echo "Using npm tag: $NPM_TAG" | |
| - name: Determine if prerelease | |
| id: prerelease | |
| run: | | |
| IS_PRERELEASE="${{ inputs.is-prerelease || 'false' }}" | |
| echo "is-prerelease=$IS_PRERELEASE" >> $GITHUB_OUTPUT | |
| echo "Is prerelease: $IS_PRERELEASE" | |
| - name: Determine release name prefix | |
| id: release-prefix | |
| run: | | |
| PREFIX="${{ inputs.release-name-prefix || 'Release' }}" | |
| echo "prefix=$PREFIX" >> $GITHUB_OUTPUT | |
| echo "Release name prefix: $PREFIX" | |
| - name: Update package.json version | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| node -e " | |
| const fs = require('fs'); | |
| const pkg = JSON.parse(fs.readFileSync('package.json', 'utf8')); | |
| pkg.version = '$VERSION'; | |
| fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2) + '\n'); | |
| " | |
| echo "Updated package.json version to $VERSION" | |
| - name: Setup Node.js (for npm publish) | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| registry-url: "https://registry.npmjs.org" | |
| - name: Upgrade npm for trusted publishing | |
| run: npm install -g npm@latest | |
| - name: Publish to npm with provenance | |
| run: npm publish --provenance --access public --tag ${{ steps.npm-tag.outputs.tag }} | |
| - name: Create Git Tag | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| PREFIX="${{ steps.release-prefix.outputs.prefix }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag -a v$VERSION -m "$PREFIX v$VERSION" | |
| git push origin v$VERSION | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ steps.version.outputs.version }} | |
| name: ${{ steps.release-prefix.outputs.prefix }} v${{ steps.version.outputs.version }} | |
| body: | | |
| ## ${{ steps.release-prefix.outputs.prefix }} v${{ steps.version.outputs.version }} | |
| ${{ steps.prerelease.outputs.is-prerelease == 'true' && 'This is a prerelease from the `dev` branch.' || 'See [CHANGELOG.md](https://github.com/integratedotdev/typescript-sdk/blob/main/CHANGELOG.md) for details.' }} | |
| ### Installation | |
| ```bash | |
| ${{ steps.npm-tag.outputs.tag == 'latest' && format('bun add integrate-sdk@{0}', steps.version.outputs.version) || format('# Install latest {0} version\nbun add integrate-sdk@{1}\n\n# Or install specific version\nbun add integrate-sdk@{2}', steps.npm-tag.outputs.tag, steps.npm-tag.outputs.tag, steps.version.outputs.version) }} | |
| ``` | |
| ${{ steps.prerelease.outputs.is-prerelease == 'true' && format('\n**Note:** Prerelease versions are published with the `{0}` tag and will not affect the `latest` tag.', steps.npm-tag.outputs.tag) || '' }} | |
| draft: false | |
| prerelease: ${{ steps.prerelease.outputs.is-prerelease == 'true' }} | |
| - name: Send Discord notification | |
| run: | | |
| if [ -z "${{ secrets.DISCORD_WEBHOOK_URL }}" ]; then | |
| echo "Discord webhook URL not set, skipping notification" | |
| exit 0 | |
| fi | |
| VERSION="${{ steps.version.outputs.version }}" | |
| PREFIX="${{ steps.release-prefix.outputs.prefix }}" | |
| NPM_TAG="${{ steps.npm-tag.outputs.tag }}" | |
| REPO="${{ github.repository }}" | |
| RELEASE_URL="https://github.com/${REPO}/releases/tag/v${VERSION}" | |
| # Determine installation command | |
| if [ "$NPM_TAG" = "latest" ]; then | |
| INSTALL_CMD="bun add integrate-sdk@$VERSION" | |
| else | |
| INSTALL_CMD="bun add integrate-sdk@$NPM_TAG" | |
| fi | |
| # Use node to construct the JSON payload | |
| PAYLOAD=$(node -e " | |
| const version = process.argv[1]; | |
| const prefix = process.argv[2]; | |
| const url = process.argv[3]; | |
| const installCmd = process.argv[4]; | |
| const payload = { | |
| embeds: [{ | |
| title: prefix + ' v' + version, | |
| description: prefix === 'Release' ? 'A new stable release has been published!' : 'A new prerelease has been published from the \`dev\` branch.', | |
| url: url, | |
| color: 1316451, | |
| fields: [{ | |
| name: 'Installation', | |
| value: '\`\`\`bash\n' + installCmd + '\n\`\`\`', | |
| inline: false | |
| }], | |
| footer: { | |
| text: 'integrate.dev' | |
| }, | |
| timestamp: new Date().toISOString() | |
| }] | |
| }; | |
| console.log(JSON.stringify(payload)); | |
| " "$VERSION" "$PREFIX" "$RELEASE_URL" "$INSTALL_CMD") | |
| curl -X POST \ | |
| -H "Content-Type: application/json" \ | |
| -d "$PAYLOAD" \ | |
| "${{ secrets.DISCORD_WEBHOOK_URL }}" |