diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..17cf01b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,75 @@ +name: Build and Release + +on: + push: + branches: + - main + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Use Node.js 20.x + uses: actions/setup-node@v4 + with: + node-version: '20.x' + + - name: Install dependencies + run: npm install + + - name: ESLint + run: npm run lint + + - name: Execute tests + run: npm test + + - name: Run build + run: npm run build + + - name: Get version from package.json + id: version + run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + + - name: Check if release tag already exists + id: tag_check + run: | + if git ls-remote --tags origin "refs/tags/v${{ steps.version.outputs.version }}" | grep -q .; then + echo "exists=true" >> $GITHUB_OUTPUT + else + echo "exists=false" >> $GITHUB_OUTPUT + fi + + - name: Commit build artifacts into release commit + if: steps.tag_check.outputs.exists == 'false' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add -f dist/ inertia-helpers/ + git commit -m "chore: build artifacts for v${{ steps.version.outputs.version }}" + + - name: Create and push version tag + if: steps.tag_check.outputs.exists == 'false' + run: | + git tag -a "v${{ steps.version.outputs.version }}" -m "Release v${{ steps.version.outputs.version }}" + git push origin "v${{ steps.version.outputs.version }}" + + - name: Create release archive + if: steps.tag_check.outputs.exists == 'false' + run: zip -r coldbox-vite-plugin-v${{ steps.version.outputs.version }}.zip dist/ inertia-helpers/ + + - name: Create GitHub Release + if: steps.tag_check.outputs.exists == 'false' + uses: softprops/action-gh-release@v2 + with: + tag_name: v${{ steps.version.outputs.version }} + name: v${{ steps.version.outputs.version }} + generate_release_notes: true + files: coldbox-vite-plugin-v${{ steps.version.outputs.version }}.zip diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml index 1625bda..6e14fda 100644 --- a/.github/workflows/update-changelog.yml +++ b/.github/workflows/update-changelog.yml @@ -6,4 +6,6 @@ on: jobs: update: + permissions: + contents: write uses: laravel/.github/.github/workflows/update-changelog.yml@main