Fix pnpm lock files for example deps (#2705) #550
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: "Release" | |
| permissions: | |
| contents: write | |
| actions: write | |
| id-token: write | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| release: | |
| name: Publish | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| package: | |
| - name: posthog-react-native | |
| - name: posthog-node | |
| - name: posthog-js-lite | |
| - name: posthog-js | |
| - name: "@posthog/core" | |
| - name: "@posthog/react" | |
| - name: "@posthog/ai" | |
| - name: "@posthog/nextjs-config" | |
| - name: "@posthog/nuxt" | |
| - name: "@posthog/rollup-plugin" | |
| - name: "@posthog/webpack-plugin" | |
| steps: | |
| - name: Checkout the repository | |
| uses: actions/checkout@v4 | |
| - name: Setup environment | |
| uses: ./.github/actions/setup | |
| with: | |
| install: false | |
| build: false | |
| - name: Get package path | |
| id: get-package-path | |
| run: | | |
| PACKAGE_PATH=$(pnpm list --filter=${{ matrix.package.name }} --json | jq -r '.[0].path') | |
| echo "path=$PACKAGE_PATH" >> "$GITHUB_OUTPUT" | |
| - name: Check ${{ matrix.package.name }} version and detect an update | |
| id: check-package-version | |
| uses: PostHog/[email protected] | |
| with: | |
| path: ${{ steps.get-package-path.outputs.path }} | |
| - name: Set up Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| ########## new package publish steps ############## | |
| - name: Install and build dependencies | |
| if: steps.check-package-version.outputs.is-new-version == 'true' | |
| run: pnpm install --frozen-lockfile && pnpm build | |
| - name: Tag repository with package_name and package_version | |
| if: steps.check-package-version.outputs.is-new-version == 'true' | |
| run: | | |
| git tag -a "${{ matrix.package.name }}@${{ steps.check-package-version.outputs.committed-version }}" -m "${{ matrix.package.name }}@${{ steps.check-package-version.outputs.committed-version }}" | |
| - name: Publish ${{ matrix.package.name }} to NPM | |
| if: steps.check-package-version.outputs.is-new-version == 'true' | |
| run: | | |
| pnpm publish --filter=${{ matrix.package.name }} --access public | |
| env: | |
| NPM_CONFIG_PROVENANCE: true | |
| - name: Push tag to GitHub | |
| if: steps.check-package-version.outputs.is-new-version == 'true' | |
| shell: bash | |
| run: | | |
| git push origin "${{ matrix.package.name }}@${{ steps.check-package-version.outputs.committed-version }}" | |
| - name: Create GitHub release | |
| if: steps.check-package-version.outputs.is-new-version == 'true' | |
| working-directory: ${{ steps.get-package-path.outputs.path }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # read from the first until the second header in the changelog file | |
| # this assumes the formatting of the file | |
| # and that this workflow is always running for the most recent entry in the file | |
| LAST_CHANGELOG_ENTRY=$(awk -v defText="see CHANGELOG.md" '/^## /{if (flag) exit; flag=1} flag && /^##$/{exit} flag; END{if (!flag) print defText}' CHANGELOG.md) | |
| # the action we used to use was archived, and made it really difficult to create a release with a body | |
| # because the LAST_CHANGELOG_ENTRY contains bash special characters so passing it between steps | |
| # was a pain. | |
| # we can use the github cli to create a release with a body | |
| # all as part of one step | |
| gh api \ | |
| --method POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| /repos/posthog/posthog-js/releases \ | |
| -f tag_name="${{ matrix.package.name }}@${{ steps.check-package-version.outputs.committed-version }}" \ | |
| -f target_commitish='main' \ | |
| -f name="${{ matrix.package.name }}@${{ steps.check-package-version.outputs.committed-version }}" \ | |
| -f body="$LAST_CHANGELOG_ENTRY" \ | |
| -F draft=false \ | |
| -F prerelease=false \ | |
| -F generate_release_notes=false | |
| ######################################################## | |
| ############## posthog-js auto-update ################## | |
| - name: Dispatch posthog upgrade for ${{ matrix.package.name }} | |
| if: matrix.package.name == 'posthog-js' && steps.check-package-version.outputs.is-new-version == 'true' | |
| run: | | |
| curl -f -X POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| https://api.github.com/repos/posthog/posthog-js/actions/workflows/posthog-upgrade.yml/dispatches \ | |
| -d '{ | |
| "ref": "main", | |
| "inputs": { | |
| "package_name": "${{ matrix.package.name }}", | |
| "package_version": "${{ steps.check-package-version.outputs.committed-version }}" | |
| } | |
| }' | |
| - name: Dispatch posthog.com upgrade for ${{ matrix.package.name }} | |
| if: matrix.package.name == 'posthog-js' && steps.check-package-version.outputs.is-new-version == 'true' | |
| run: | | |
| curl -f -X POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| https://api.github.com/repos/posthog/posthog-js/actions/workflows/posthog-com-upgrade.yml/dispatches \ | |
| -d '{ | |
| "ref": "main", | |
| "inputs": { | |
| "package_name": "${{ matrix.package.name }}", | |
| "package_version": "${{ steps.check-package-version.outputs.committed-version }}" | |
| } | |
| }' | |
| #################################################### | |
| # https://us.posthog.com/project/11213/functions/019ae9c0-03ee-0000-2f32-971f64be8ffe | |
| - name: Send failure event to PostHog | |
| if: ${{ failure() }} | |
| uses: PostHog/[email protected] | |
| with: | |
| posthog-token: "${{ secrets.POSTHOG_PROJECT_API_KEY }}" | |
| event: "posthog-js-github-release-workflow-failure" | |
| properties: >- | |
| { | |
| "commitSha": "${{ github.sha }}", | |
| "jobStatus": "${{ job.status }}", | |
| "commitMessage": "${{ github.event.head_commit.message }}", | |
| "commitAuthor": "${{ github.event.head_commit.author.name }}", | |
| "ref": "${{ github.ref }}", | |
| "packageName": "${{ matrix.package.name }}", | |
| "packageVersion": "${{ steps.check-package-version.outputs.committed-version }}" | |
| } |