feat: liveramp integration #334
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 NPM Package | |
| # This workflow is triggered by either: | |
| # - A "beta release" label being added to a PR which publishes a beta version of the bundle to npm | |
| # - The success of the CI workflow on the main branch, which runs the changeset command to recognise new version candidates and releases to NPM | |
| # In both cases, a changeset needs to be present for this to have any effect. Use `pnpm changeset` to add a new changeset | |
| on: | |
| # Trigger on a label being added to a PR, and publish a canary versions of all packages with waiting changesets to npm. | |
| # This action will release the changeset as a pre-release, and add a comment to the PR with the version number | |
| pull_request: | |
| types: [labeled] | |
| # Trigger for standard (changesets) release after CI on main | |
| # If a changeset PR is merged to main, this will publish a new version of the package to npm | |
| workflow_run: | |
| workflows: [CI] | |
| branches: [main] | |
| types: [completed] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| id-token: write | |
| jobs: | |
| publish: | |
| name: Core Changesets | |
| runs-on: ubuntu-latest | |
| # Only run the `publish` job if CI is successful | |
| if: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/[email protected] | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Set up Node | |
| uses: ./.github/actions/setup-node-env | |
| - name: Build package | |
| run: pnpm build:core | |
| - name: Use GitHub App Token | |
| uses: actions/create-github-app-token@v2 | |
| id: app-token | |
| with: | |
| app-id: ${{ secrets.GU_CHANGESETS_APP_ID }} | |
| private-key: ${{ secrets.GU_CHANGESETS_PRIVATE_KEY }} | |
| - name: Set git user to Gu Changesets app | |
| run: | | |
| git config user.name "gu-changesets-release-pr[bot]" | |
| git config user.email "gu-changesets-release-pr[bot]@users.noreply.github.com" | |
| - name: Create Release Pull Request or Publish to npm | |
| id: changesets | |
| uses: changesets/[email protected] | |
| with: | |
| publish: pnpm changeset publish | |
| title: 🦋 Release package updates | |
| commit: Bump package versions | |
| setupGitUser: false | |
| env: | |
| GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} | |
| publish-beta: | |
| name: '@guardian/commercial-core' | |
| runs-on: ubuntu-latest | |
| # Only run the `publish-beta` job if the correct label has been added to the PR | |
| if: github.event.label.name == '[beta] @guardian/commercial-core' | |
| steps: | |
| - name: Check if organization member | |
| id: is_organization_member | |
| uses: JamesSingleton/[email protected] | |
| with: | |
| organization: guardian | |
| username: ${{ github.actor }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Checkout | |
| uses: actions/[email protected] | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Node | |
| uses: ./.github/actions/setup-node-env | |
| - name: Build package | |
| run: pnpm build:core | |
| - name: Version | |
| run: pnpm changeset version --snapshot beta | |
| - name: Create Release | |
| uses: changesets/[email protected] | |
| id: changeset | |
| with: | |
| publish: pnpm changeset publish --tag beta | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Comment on PR | |
| uses: actions/[email protected] | |
| with: | |
| github-token: ${{secrets.GITHUB_TOKEN}} | |
| script: | | |
| const publishedPackages = ${{ steps.changeset.outputs.publishedPackages }}; | |
| if(publishedPackages.length === 0) { | |
| throw new Error('No packages published, did you forget to add a changeset?'); | |
| } | |
| const version = publishedPackages[0].version; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `🚀 \`${version}\` published to npm as a beta release | |
| To install the beta version, run one of the following commands in your project directory: | |
| \`\`\` | |
| npm install @guardian/commercial-core@${version} | |
| pnpm add @guardian/commercial-core@${version} | |
| yarn add @guardian/commercial-core@${version} | |
| \`\`\` | |
| ` | |
| }) | |
| - name: Remove label | |
| uses: actions/[email protected] | |
| if: always() | |
| with: | |
| github-token: ${{secrets.GITHUB_TOKEN}} | |
| script: | | |
| github.rest.issues.removeLabel({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| name: '[beta] @guardian/commercial-core' | |
| }) |