github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/.github/workflows/publish-lib-to-npm.yml (about)

     1  name: Publish packages to npmjs
     2  
     3  on:
     4    push:
     5      branches: [main]
     6    pull_request:
     7      branches: [main]
     8  
     9  jobs:
    10    check:
    11      runs-on: ubuntu-latest
    12      outputs:
    13        inputsChecked: ${{ steps.github_token_gate.outputs.inputsChecked }}
    14      steps:
    15        - uses: svrooij/secret-gate-action@v1
    16          id: github_token_gate
    17          with:
    18            inputsToCheck: 'token'
    19          env:
    20            token: ${{ secrets.BOT_GITHUB_TOKEN }}
    21    build:
    22      # skip if user has not access to the token
    23      if: needs.check.outputs.inputsChecked == 'true'
    24      runs-on: ubuntu-latest
    25      needs: check
    26      steps:
    27        #######################
    28        #      Checkout      #
    29        ######################
    30        # For non-pull requests, fetch all tags
    31        - uses: actions/checkout@v2
    32          if: github.event_name != 'pull_request'
    33          with:
    34            fetch-depth: 0
    35            token: ${{ secrets.BOT_GITHUB_TOKEN }}
    36        # For pull requests, also checkout out the REAL commit (as opposed to a merge commit with main)
    37        - uses: actions/checkout@v2
    38          if: github.event_name == 'pull_request'
    39          # For PRs check the actual commit
    40          # https://github.com/actions/checkout/issues/124#issuecomment-586664611
    41          # https://github.com/actions/checkout/issues/455#issuecomment-792228083
    42          with:
    43            fetch-depth: 0
    44            token: ${{ secrets.BOT_GITHUB_TOKEN }}
    45            ref: ${{ github.event.pull_request.head.ref }}
    46            repository: ${{github.event.pull_request.head.repo.full_name}}
    47  
    48        # pull all tags since they are required when generating locally
    49        # https://github.com/lerna/lerna/issues/2542
    50        - run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
    51          if: github.event_name == 'pull_request'
    52  
    53        # Setup .npmrc file to publish to npm
    54        - uses: actions/setup-node@v2
    55          with:
    56            node-version: '16.18'
    57            registry-url: 'https://registry.npmjs.org'
    58  
    59        - name: Get yarn cache directory path
    60          id: yarn-cache-dir-path
    61          run: echo "::set-output name=dir::$(yarn cache dir)"
    62  
    63        - name: Prepare
    64          id: prep
    65          run: |
    66            TAG=$(echo $GITHUB_SHA | head -c7)
    67            echo ::set-output name=tag::${TAG}
    68  
    69        - uses: actions/cache@v2
    70          id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
    71          with:
    72            path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
    73            key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
    74            restore-keys: |
    75              ${{ runner.os }}-yarn
    76  
    77        - name: Install Webapp dependencies
    78          run: yarn install --frozen-lockfile
    79  
    80        # This step will bump the package.json version and NOT push to the repository
    81        # this is needed since building grafana requires updating the plugin.json file
    82        # with the package.json version
    83        - name: Bump version, generate changelog etc
    84          if: github.event_name == 'pull_request'
    85          run: |
    86            # Copied from https://github.com/pyroscope-io/pyroscope/blob/main/.github/workflows/update-contributors.yml#L23-L28
    87            git config --global user.email "dmitry+bot@pyroscope.io"
    88            git config --global user.name "Pyroscope Bot <dmitry+bot@pyroscope.io>"
    89            yarn run lerna version --conventional-commits --conventional-prerelease --yes --no-push --preid=${{ github.event.pull_request.number }}-${{ steps.prep.outputs.tag }}
    90  
    91        # This step will bump the package.json version, generate a CHANGELOG.md
    92        # And commit to the repository
    93        - name: Bump version, generate changelog etc
    94          if: github.event_name != 'pull_request'
    95          run: |
    96            # Copied from https://github.com/pyroscope-io/pyroscope/blob/main/.github/workflows/update-contributors.yml#L23-L28
    97            git config --global user.email "dmitry+bot@pyroscope.io"
    98            git config --global user.name "Pyroscope Bot <dmitry+bot@pyroscope.io>"
    99            yarn run lerna version --conventional-commits --yes
   100          env:
   101            GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}
   102  
   103        # build all packages
   104        - name: Build
   105          run: yarn run lerna run build
   106  
   107        #####################
   108        #      Publish      #
   109        #####################
   110        - name: Publish Main
   111          if: github.event_name != 'pull_request'
   112          run: |
   113            yarn run lerna publish from-package \
   114            --skip-git \
   115            --conventional-commits \
   116            --yes \
   117            --no-verify-access
   118          env:
   119            NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
   120  
   121        - name: Publish Pull Request
   122          # Only publish if it comes from the main repo
   123          if: (github.event_name == 'pull_request') && (github.event.pull_request.head.repo.full_name == github.repository)
   124          run: |
   125            yarn run lerna publish from-git \
   126              --skip-git \
   127              --conventional-commits \
   128              --yes \
   129              --no-verify-access \
   130              --force-publish='*' \
   131              --canary
   132          env:
   133            NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}