|
| 1 | +name: CI and Release |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: [main] |
| 6 | + types: [opened, synchronize, reopened] |
| 7 | + push: |
| 8 | + branches: [main] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | +jobs: |
| 19 | + test-and-release: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: Check version tag does not exist |
| 26 | + run: | |
| 27 | + VERSION=$(node -p "require('./package.json').version") |
| 28 | + if git ls-remote --tags origin | grep -q "refs/tags/v${VERSION}$"; then |
| 29 | + echo "::error::Tag v${VERSION} already exists. Bump version in package.json first." |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | + echo "VERSION=${VERSION}" >> $GITHUB_ENV |
| 33 | +
|
| 34 | + - name: Setup Node.js |
| 35 | + uses: actions/setup-node@v4 |
| 36 | + with: |
| 37 | + node-version: '20' |
| 38 | + cache: 'npm' |
| 39 | + |
| 40 | + - name: Install dependencies |
| 41 | + run: npm ci |
| 42 | + |
| 43 | + - name: Run tests |
| 44 | + run: npm test |
| 45 | + |
| 46 | + - name: Create version tags |
| 47 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 48 | + run: | |
| 49 | + VERSION="${{ env.VERSION }}" |
| 50 | + MAJOR=$(echo "$VERSION" | cut -d. -f1) |
| 51 | +
|
| 52 | + git config user.name "github-actions[bot]" |
| 53 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 54 | +
|
| 55 | + git tag "v${VERSION}" |
| 56 | + git tag -f "v${MAJOR}" |
| 57 | + git push origin "v${VERSION}" "+v${MAJOR}" |
| 58 | +
|
| 59 | + - name: Write job summary |
| 60 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 61 | + run: | |
| 62 | + VERSION="${{ env.VERSION }}" |
| 63 | + MAJOR=$(echo "$VERSION" | cut -d. -f1) |
| 64 | + SHA="${{ github.sha }}" |
| 65 | +
|
| 66 | + cat >> $GITHUB_STEP_SUMMARY << EOF |
| 67 | + ## Release Summary |
| 68 | +
|
| 69 | + | Item | Value | |
| 70 | + |--------------|----------------------------------| |
| 71 | + | Version | \`${VERSION}\` | |
| 72 | + | Commit | \`${SHA:0:7}\` | |
| 73 | + | Tags Created | \`v${VERSION}\`, \`v${MAJOR}\` | |
| 74 | +
|
| 75 | + Users can reference this action as: |
| 76 | + - \`uses: boldtrail/pr-integration-action@v${VERSION}\` - exact version |
| 77 | + - \`uses: boldtrail/pr-integration-action@v${MAJOR}\` - latest v${MAJOR}.x.x |
| 78 | + EOF |
0 commit comments