Changes generated by d97c5f53b394eaa852733dc030b77590b491794c #90
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
| name: test & publish | |
| on: push | |
| permissions: | |
| id-token: write # Required for OIDC | |
| contents: write # Required for creating releases and tags | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: node:lts | |
| steps: | |
| - uses: actions/checkout@v3.3.0 | |
| - run: npm install --save-dev jest typescript ts-jest @types/jest | |
| - run: npm test | |
| transpile: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: node:lts | |
| needs: | |
| - test | |
| steps: | |
| - uses: actions/checkout@v3.3.0 | |
| - run: npm install | |
| - run: npm install -g typescript | |
| - run: npm run build | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| path: "dist" | |
| check_version: | |
| if: github.ref == 'refs/heads/master' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_publish: ${{ steps.check.outputs.should_publish }} | |
| version: ${{ steps.check.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v3.3.0 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check if version tag exists | |
| id: check | |
| run: | | |
| VERSION=$(node -p "require('./package.json').version") | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| if git rev-parse "v${VERSION}" >/dev/null 2>&1; then | |
| echo "Tag v${VERSION} already exists, skipping publish" | |
| echo "should_publish=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "Tag v${VERSION} does not exist, will publish" | |
| echo "should_publish=true" >> $GITHUB_OUTPUT | |
| fi | |
| publish_to_npm: | |
| if: github.ref == 'refs/heads/master' && needs.check_version.outputs.should_publish == 'true' | |
| runs-on: ubuntu-latest | |
| container: | |
| image: node:lts | |
| needs: | |
| - transpile | |
| - check_version | |
| env: | |
| DIST_FOLDER: "/dist/artifact" | |
| steps: | |
| - uses: actions/checkout@v3.3.0 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| path: "/dist" | |
| - run: cp package.json $DIST_FOLDER | |
| - run: cp README.md $DIST_FOLDER | |
| - run: npm install | |
| - name: Publish the library. | |
| run: npm publish $DIST_FOLDER | |
| create_release: | |
| if: github.ref == 'refs/heads/master' && needs.check_version.outputs.should_publish == 'true' | |
| runs-on: ubuntu-latest | |
| needs: | |
| - publish_to_npm | |
| - check_version | |
| steps: | |
| - uses: actions/checkout@v3.3.0 | |
| with: | |
| fetch-depth: 0 | |
| - name: Create tag and release | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git tag v${{ needs.check_version.outputs.version }} | |
| git push origin v${{ needs.check_version.outputs.version }} | |
| gh release create v${{ needs.check_version.outputs.version }} --generate-notes | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |