|  | 
|  | 1 | +name: GitHub release and NPM publishing | 
|  | 2 | + | 
|  | 3 | +# From: https://github.com/garronej/ts-ci | 
|  | 4 | +on: | 
|  | 5 | +  push: | 
|  | 6 | +    branches: | 
|  | 7 | +      - main | 
|  | 8 | + | 
|  | 9 | +jobs: | 
|  | 10 | +  check_if_version_upgraded: | 
|  | 11 | +    name: Check if version upgrade | 
|  | 12 | +    # When someone forks the repo and opens a PR we want to enables the tests to be run (the previous jobs) | 
|  | 13 | +    # but obviously only us should be allowed to release. | 
|  | 14 | +    # In the following check we make sure that we own the branch this CI workflow is running on before continuing. | 
|  | 15 | +    # Without this check, trying to release would fail anyway because only us have the correct secret.NPM_TOKEN but | 
|  | 16 | +    # it's cleaner to stop the execution instead of letting the CI crash. | 
|  | 17 | +    if: | | 
|  | 18 | +      github.event_name == 'push' || | 
|  | 19 | +      github.event.pull_request.head.repo.owner.login == github.event.pull_request.base.repo.owner.login | 
|  | 20 | +    runs-on: ubuntu-latest | 
|  | 21 | +    outputs: | 
|  | 22 | +      from_version: ${{ steps.step1.outputs.from_version }} | 
|  | 23 | +      to_version: ${{ steps.step1.outputs.to_version }} | 
|  | 24 | +      is_upgraded_version: ${{ steps.step1.outputs.is_upgraded_version }} | 
|  | 25 | +      is_pre_release: ${{steps.step1.outputs.is_pre_release }} | 
|  | 26 | +    steps: | 
|  | 27 | +      - uses: garronej/ts-ci@v2.1.0 | 
|  | 28 | +        id: step1 | 
|  | 29 | +        with: | 
|  | 30 | +          action_name: is_package_json_version_upgraded | 
|  | 31 | +          branch: ${{ github.head_ref || github.ref }} | 
|  | 32 | + | 
|  | 33 | +  create_github_release: | 
|  | 34 | +    runs-on: ubuntu-latest | 
|  | 35 | +    # We create release only if the version in the package.json have been | 
|  | 36 | +    # upgraded and this CI is running against the main branch. We allow | 
|  | 37 | +    # branches with a PR open on main to publish pre-release (x.y.z-rc.u) but | 
|  | 38 | +    # not actual releases. | 
|  | 39 | +    if: | | 
|  | 40 | +      needs.check_if_version_upgraded.outputs.is_upgraded_version == 'true' && | 
|  | 41 | +      ( | 
|  | 42 | +        github.event_name == 'push' || | 
|  | 43 | +        needs.check_if_version_upgraded.outputs.is_pre_release == 'true' | 
|  | 44 | +      ) | 
|  | 45 | +    needs: | 
|  | 46 | +      - check_if_version_upgraded | 
|  | 47 | +    steps: | 
|  | 48 | +      - uses: softprops/action-gh-release@v1 | 
|  | 49 | +        with: | 
|  | 50 | +          name: Release v${{ needs.check_if_version_upgraded.outputs.to_version }} | 
|  | 51 | +          tag_name: v${{ needs.check_if_version_upgraded.outputs.to_version }} | 
|  | 52 | +          target_commitish: ${{ github.head_ref || github.ref }} | 
|  | 53 | +          generate_release_notes: true | 
|  | 54 | +          draft: false | 
|  | 55 | +          prerelease: ${{ needs.check_if_version_upgraded.outputs.is_pre_release == 'true'}} | 
|  | 56 | +        env: | 
|  | 57 | +          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | 
|  | 58 | + | 
|  | 59 | +  # deploy_gh_page: | 
|  | 60 | +  #   runs-on: ubuntu-latest | 
|  | 61 | +  #   needs: | 
|  | 62 | +  #     - create_github_release | 
|  | 63 | +  #     - check_if_version_upgraded | 
|  | 64 | +  #   steps: | 
|  | 65 | +  #     - name: Checkout | 
|  | 66 | +  #       uses: actions/checkout@v3 | 
|  | 67 | +  #     - name: Install dependencies and build | 
|  | 68 | +  #       run: yarn install --immutable && yarn install --immutable --cwd doc | 
|  | 69 | +  #     - run: yarn run doc:build | 
|  | 70 | +  #     - name: Deploy | 
|  | 71 | +  #       uses: crazy-max/ghaction-github-pages@v3 | 
|  | 72 | +  #       with: | 
|  | 73 | +  #         target_branch: gh-pages | 
|  | 74 | +  #         build_dir: doc/build | 
|  | 75 | +  #         jekyll: false | 
|  | 76 | +  #       env: | 
|  | 77 | +  #         GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | 
|  | 78 | + | 
|  | 79 | +  publish_on_npm: | 
|  | 80 | +    runs-on: ubuntu-latest | 
|  | 81 | +    needs: | 
|  | 82 | +      - create_github_release | 
|  | 83 | +      - check_if_version_upgraded | 
|  | 84 | +    steps: | 
|  | 85 | +      - uses: actions/checkout@v3 | 
|  | 86 | +        with: | 
|  | 87 | +          ref: ${{ github.ref }} | 
|  | 88 | +      - name: Setup .npmrc file to publish to npm | 
|  | 89 | +        uses: actions/setup-node@v3 | 
|  | 90 | +        with: | 
|  | 91 | +          node-version: 22 | 
|  | 92 | +          registry-url: "https://registry.npmjs.org" | 
|  | 93 | +      - name: Install dependencies | 
|  | 94 | +        run: yarn install --immutable | 
|  | 95 | +      - name: Prepare packaging | 
|  | 96 | +        run: yarn prepack | 
|  | 97 | +      - name: Publish to NPM | 
|  | 98 | +        run: npm publish | 
|  | 99 | +        env: | 
|  | 100 | +          NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | 
0 commit comments