|
| 1 | +name: Build and Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Use Node.js 20.x |
| 21 | + uses: actions/setup-node@v4 |
| 22 | + with: |
| 23 | + node-version: '20.x' |
| 24 | + |
| 25 | + - name: Install dependencies |
| 26 | + run: npm install |
| 27 | + |
| 28 | + - name: ESLint |
| 29 | + run: npm run lint |
| 30 | + |
| 31 | + - name: Execute tests |
| 32 | + run: npm test |
| 33 | + |
| 34 | + - name: Run build |
| 35 | + run: npm run build |
| 36 | + |
| 37 | + - name: Get version from package.json |
| 38 | + id: version |
| 39 | + run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT |
| 40 | + |
| 41 | + - name: Check if release tag already exists |
| 42 | + id: tag_check |
| 43 | + run: | |
| 44 | + if git ls-remote --tags origin "refs/tags/v${{ steps.version.outputs.version }}" | grep -q .; then |
| 45 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 46 | + else |
| 47 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 48 | + fi |
| 49 | +
|
| 50 | + - name: Commit build artifacts into release commit |
| 51 | + if: steps.tag_check.outputs.exists == 'false' |
| 52 | + run: | |
| 53 | + git config user.name "github-actions[bot]" |
| 54 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 55 | + git add -f dist/ inertia-helpers/ |
| 56 | + git commit -m "chore: build artifacts for v${{ steps.version.outputs.version }}" |
| 57 | +
|
| 58 | + - name: Create and push version tag |
| 59 | + if: steps.tag_check.outputs.exists == 'false' |
| 60 | + run: | |
| 61 | + git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}" |
| 62 | + git push origin "v${{ steps.version.outputs.version }}" |
| 63 | +
|
| 64 | + - name: Create release archive |
| 65 | + if: steps.tag_check.outputs.exists == 'false' |
| 66 | + run: zip -r coldbox-vite-plugin-v${{ steps.version.outputs.version }}.zip dist/ inertia-helpers/ |
| 67 | + |
| 68 | + - name: Create GitHub Release |
| 69 | + if: steps.tag_check.outputs.exists == 'false' |
| 70 | + uses: softprops/action-gh-release@v2 |
| 71 | + with: |
| 72 | + tag_name: v${{ steps.version.outputs.version }} |
| 73 | + name: v${{ steps.version.outputs.version }} |
| 74 | + generate_release_notes: true |
| 75 | + files: coldbox-vite-plugin-v${{ steps.version.outputs.version }}.zip |
0 commit comments