feat: add utility method for type-safe yields (#6) #13
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
| # This is a composition of lint and test scripts | |
| name: Test and Release | |
| # Run this job on pushes to master and pull requests | |
| # as well as tags with a semantic version | |
| on: | |
| push: | |
| branches: | |
| - "main" | |
| tags: | |
| # normal versions | |
| - "v[0-9]+.[0-9]+.[0-9]+" | |
| # pre-releases | |
| - "v[0-9]+.[0-9]+.[0-9]+-**" | |
| pull_request: {} | |
| jobs: | |
| # Runs unit tests on all supported node versions and OSes | |
| unit-tests: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| node-version: [20, 22] | |
| os: [ubuntu-latest] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Enable Corepack | |
| shell: bash | |
| run: corepack enable | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: 'yarn' | |
| - name: Install dependencies | |
| run: yarn install --frozen-lockfile | |
| - name: Compile | |
| run: yarn build | |
| - name: Run component tests | |
| run: yarn test | |
| env: | |
| CI: true | |
| # =================== | |
| # Deploys the final package to NPM and Github Actions | |
| deploy: | |
| # Trigger this step only when a commit on master is tagged with a version number | |
| if: | | |
| github.event_name == 'push' && | |
| startsWith(github.ref, 'refs/tags/v') | |
| needs: [unit-tests] | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| node-version: [22] | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Enable Corepack | |
| shell: bash | |
| run: corepack enable | |
| - name: Use Node.js ${{ matrix.node-version }} | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ matrix.node-version }} | |
| cache: 'yarn' | |
| - name: Extract the version and commit body from the tag | |
| id: extract_release | |
| # The body may be multiline, therefore we need to escape some characters | |
| run: | | |
| VERSION="${{ github.ref }}" | |
| VERSION=${VERSION##*/v} | |
| echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
| EOF=$(od -An -N6 -x /dev/urandom | tr -d ' ') | |
| BODY=$(git show -s --format=%b) | |
| echo "BODY<<$EOF" >> $GITHUB_OUTPUT | |
| echo "$BODY" >> $GITHUB_OUTPUT | |
| echo "$EOF" >> $GITHUB_OUTPUT | |
| if [[ $VERSION == *"-"* ]] ; then | |
| echo "TAG=--tag next" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Install dependencies | |
| run: yarn install --frozen-lockfile | |
| - name: Create a clean build | |
| run: yarn run build | |
| - name: Publish packages to npm | |
| env: | |
| TAG: ${{ steps.extract_release.outputs.TAG }} | |
| run: | | |
| yarn config set npmAuthToken "${{ secrets.NPM_TOKEN }}" | |
| yarn npm whoami | |
| yarn workspaces foreach --all -vti --no-private npm publish --tolerate-republish $TAG | |
| - name: Create Github Release | |
| uses: softprops/action-gh-release@v2 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ github.ref }} | |
| name: Release v${{ steps.extract_release.outputs.VERSION }} | |
| draft: false | |
| # Prerelease versions create prereleases on Github | |
| prerelease: ${{ contains(steps.extract_release.outputs.VERSION, '-') }} | |
| body: ${{ steps.extract_release.outputs.BODY }} |