|
| 1 | +name: Publish |
| 2 | +on: |
| 3 | + release: |
| 4 | + types: published |
| 5 | +permissions: |
| 6 | + contents: write |
| 7 | + |
| 8 | +jobs: |
| 9 | + build: |
| 10 | + name: Build |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v5 |
| 14 | + - name: Configure git |
| 15 | + run: | |
| 16 | + git config user.name 'Release Action' |
| 17 | + git config user.email '<>' |
| 18 | + - uses: actions/setup-node@v5 |
| 19 | + with: |
| 20 | + node-version: 20 |
| 21 | + |
| 22 | + # Update package.json version to match the release tag |
| 23 | + - name: Update package version |
| 24 | + run: | |
| 25 | + git tag -d "${{ github.event.release.tag_name }}" |
| 26 | + VERSION=$(npm version "${{ github.event.release.tag_name }}" --no-git-tag-version) |
| 27 | + git add package.json package-lock.json |
| 28 | + git commit -m "[skip ci] Bump $VERSION" |
| 29 | + git push origin HEAD:main |
| 30 | + |
| 31 | + # Build and test |
| 32 | + - name: Perform npm tasks |
| 33 | + run: npm run ci |
| 34 | + |
| 35 | + # Create release with built artifacts |
| 36 | + - name: Create release artifacts |
| 37 | + run: | |
| 38 | + # Validate semantic versioning |
| 39 | + longVersion="${{github.event.release.tag_name}}" |
| 40 | + echo "Preparing release for version $longVersion" |
| 41 | + [[ $longVersion == v[0-9]*.[0-9]*.[0-9]* ]] || (echo "must follow semantic versioning" && exit 1) |
| 42 | +
|
| 43 | + # Add the built artifacts (adjust folder names as needed) |
| 44 | + git add --force dist lib |
| 45 | +
|
| 46 | + # Create commit with built code |
| 47 | + MESSAGE="Build for $(git rev-parse --short HEAD)" |
| 48 | + git commit --allow-empty -m "$MESSAGE" |
| 49 | + |
| 50 | + # Tag this commit with the release version |
| 51 | + git tag -f -a -m "Release $longVersion" $longVersion |
| 52 | + |
| 53 | + # Push the release tag |
| 54 | + git push -f origin $longVersion |
0 commit comments