|
| 1 | +# This file is a generic workflow used across multiple Intercom repos. |
| 2 | +# The source of truth lives at: |
| 3 | +# https://github.com/intercom/github-action-workflows |
| 4 | +# If you feel you need to make a change to this workflow, please reach out |
| 5 | +# to team-builder-tools on Slack. |
| 6 | + |
| 7 | +name: Publish pre-release version to GitHub Package Registry |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + branches-ignore: |
| 12 | + - main |
| 13 | + |
| 14 | +jobs: |
| 15 | + publish: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout repository |
| 19 | + uses: actions/checkout@v2 |
| 20 | + |
| 21 | + - name: Fetch all tags |
| 22 | + run: git fetch --depth=1 origin +refs/tags/*:refs/tags/* |
| 23 | + |
| 24 | + - name: Setup NodeJS Runtime |
| 25 | + uses: actions/setup-node@v2 |
| 26 | + with: |
| 27 | + node-version: 18 |
| 28 | + registry-url: 'https://npm.pkg.github.com' |
| 29 | + scope: '@intercom' |
| 30 | + |
| 31 | + - name: Check version changes |
| 32 | + run: echo "##[set-output name=is-pre-release;]$(node -e 'console.log(require(`./package.json`).version.includes(`-`))')" |
| 33 | + id: package-version-check |
| 34 | + |
| 35 | + - name: Publish new tag |
| 36 | + if: steps.package-version-check.outputs.is-pre-release == 'true' |
| 37 | + run: | |
| 38 | + package_version="v$(node -e "console.log(require('./package.json').version)")" |
| 39 | + tag_existed_before=$(git tag --list | grep "$package_version" | wc -l) |
| 40 | + if [ "$tag_existed_before" == "0" ]; then |
| 41 | + git config --global user.email "[email protected]" |
| 42 | + git config --global user.name "intercom/github-action-workflows - Auto-Tag - GitHub Action" |
| 43 | + git tag -a "$package_version" -m "$package_version" |
| 44 | + git push origin "$package_version" |
| 45 | + echo "Pushed tag $package_version" |
| 46 | + else |
| 47 | + echo "Tag $package_version already exists, not overwriting" |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Install dependencies |
| 51 | + if: steps.package-version-check.outputs.is-pre-release == 'true' |
| 52 | + run: yarn install --frozen-lockfile |
| 53 | + |
| 54 | + - name: Publish to GPR |
| 55 | + if: steps.package-version-check.outputs.is-pre-release == 'true' |
| 56 | + # We need to remove the .npmrc here because it contains a read-only |
| 57 | + # GPR token which takes precendence over the read-write token |
| 58 | + # provided by GitHub via action secrets below |
| 59 | + run: rm .npmrc || true; npm publish || true |
| 60 | + env: |
| 61 | + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments