|
| 1 | +name: 'Release' |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - master |
| 8 | + |
| 9 | +jobs: |
| 10 | + release: |
| 11 | + name: Bake a Release |
| 12 | + runs-on: ubuntu-20.04 |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout the repository |
| 16 | + uses: actions/checkout@v2 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Get package version |
| 21 | + id: version |
| 22 | + run: | |
| 23 | + PACKAGE_VERSION=$(node -p "require('./package.json').version") |
| 24 | + PACKAGE_VERSION_TAG="v$PACKAGE_VERSION" |
| 25 | + if git rev-parse "$PACKAGE_VERSION_TAG"; then |
| 26 | + IS_NEW_VERSION=false |
| 27 | + else |
| 28 | + IS_NEW_VERSION=true |
| 29 | + fi |
| 30 | + echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV |
| 31 | + echo "PACKAGE_VERSION_TAG=$PACKAGE_VERSION_TAG" >> $GITHUB_ENV |
| 32 | + echo "IS_NEW_VERSION=$IS_NEW_VERSION" >> $GITHUB_ENV |
| 33 | + echo "::set-output name=IS_NEW_VERSION::$IS_NEW_VERSION" |
| 34 | +
|
| 35 | + - name: Set up Node 14 |
| 36 | + if: steps.version.outputs.IS_NEW_VERSION == 'true' |
| 37 | + uses: actions/setup-node@v2 |
| 38 | + with: |
| 39 | + node-version: 14 |
| 40 | + registry-url: https://registry.npmjs.org |
| 41 | + |
| 42 | + - name: Install dependencies |
| 43 | + if: steps.version.outputs.IS_NEW_VERSION == 'true' |
| 44 | + run: yarn --frozen-lockfile |
| 45 | + |
| 46 | + - name: Publish the package in the npm registry |
| 47 | + if: steps.version.outputs.IS_NEW_VERSION == 'true' |
| 48 | + run: yarn publish --access public |
| 49 | + env: |
| 50 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 51 | + |
| 52 | + - name: Create GitHub release |
| 53 | + if: steps.version.outputs.IS_NEW_VERSION == 'true' |
| 54 | + uses: actions/create-release@v1 |
| 55 | + env: |
| 56 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 57 | + with: |
| 58 | + tag_name: ${{ env.PACKAGE_VERSION_TAG }} |
| 59 | + release_name: ${{ env.PACKAGE_VERSION }} |
| 60 | + |
| 61 | + # if the package is @scoped, uncomment GitHub Packages release below |
| 62 | + |
| 63 | + # - name: Switch to the GitHub registry |
| 64 | + # if: steps.version.outputs.IS_NEW_VERSION == 'true' |
| 65 | + # uses: actions/setup-node@v2 |
| 66 | + # with: |
| 67 | + # node-version: 14 |
| 68 | + # registry-url: https://npm.pkg.github.com |
| 69 | + |
| 70 | + # - name: Publish the package in the GitHub registry |
| 71 | + # if: steps.version.outputs.IS_NEW_VERSION == 'true' |
| 72 | + # run: yarn publish --access public |
| 73 | + # env: |
| 74 | + # NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments