name: CI on: push: branches: ["main"] tags: ["v*"] pull_request: branches: ["main"] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: node-version: 20 cache: npm - name: Install dependencies run: npm ci - name: Build run: npm run build - name: Check dist is up to date if: github.ref_type != 'tag' run: | if [ -n "$(git status --short dist/)" ]; then echo "dist/ is out of date. Run 'npm run build' and commit the result." git diff dist/ exit 1 fi release: runs-on: ubuntu-latest needs: build if: github.ref_type == 'tag' permissions: contents: write steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: node-version: 20 cache: npm - name: Install dependencies run: npm ci - name: Build run: npm run build - name: Make sure tag matches package.json version run: | TAG_VERSION="${GITHUB_REF#refs/tags/}" PACKAGE_VERSION=$(node -p "require('./package.json').version") if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then echo "Tag version ($TAG_VERSION) does not match package.json version ($PACKAGE_VERSION)" exit 1 fi - name: Commit dist to tag run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" git add --force dist/ git commit -m "chore: build dist for ${{ github.ref_name }}" || echo "Nothing to commit" git tag -f ${{ github.ref_name }} git push origin ${{ github.ref_name }} --force - name: Create GitHub Release uses: softprops/action-gh-release@v2 with: generate_release_notes: true