diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..fab9ead --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,129 @@ +name: Release + +on: + push: + branches: + - main + workflow_dispatch: + +permissions: + contents: write + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Build + run: npm run build + + - name: Archive build artifacts + run: | + cd public + zip -r ../redact-check-build.zip . + cd .. + + - name: Upload build artifact + uses: actions/upload-artifact@v4 + with: + name: build-artifacts + path: redact-check-build.zip + + release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Fetch all history for changelog generation + + - name: Get version from package.json + id: version + run: | + VERSION=$(node -p "require('./package.json').version") + echo "version=v${VERSION}" >> $GITHUB_OUTPUT + echo "Version: v${VERSION}" + + - name: Download build artifact + uses: actions/download-artifact@v4 + with: + name: build-artifacts + + - name: Generate changelog + id: changelog + run: | + # Get the latest tag (if exists) + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") + + COMMIT_SHA="${{ github.sha }}" + SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-7) + + if [ -z "$LATEST_TAG" ]; then + # No previous tags, show last 10 commits + CHANGELOG=$(git log --pretty=format:"- %s ([%h](https://github.com/${{ github.repository }}/commit/%H))" -10) + FILES_CHANGED=$(git diff --stat ${COMMIT_SHA}~10..${COMMIT_SHA} --stat-width=80 | tail -1) + COMPARE_URL="" + PREVIOUS_TAG="Initial release" + else + # Get commits since last tag + CHANGELOG=$(git log ${LATEST_TAG}..${COMMIT_SHA} --pretty=format:"- %s ([%h](https://github.com/${{ github.repository }}/commit/%H))") + FILES_CHANGED=$(git diff --stat ${LATEST_TAG}..${COMMIT_SHA} --stat-width=80 | tail -1) + COMPARE_URL="https://github.com/${{ github.repository }}/compare/${LATEST_TAG}...${SHORT_SHA}" + PREVIOUS_TAG="$LATEST_TAG" + fi + + # Handle empty changelog + if [ -z "$CHANGELOG" ]; then + CHANGELOG="- ${{ github.event.head_commit.message }} ([$SHORT_SHA](https://github.com/${{ github.repository }}/commit/$COMMIT_SHA))" + fi + + # Output using multiline string + echo "changes<> $GITHUB_OUTPUT + echo "$CHANGELOG" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + echo "files_changed=$FILES_CHANGED" >> $GITHUB_OUTPUT + echo "compare_url=$COMPARE_URL" >> $GITHUB_OUTPUT + echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT + echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT + + - name: Create Release + uses: softprops/action-gh-release@v1 + with: + tag_name: ${{ steps.version.outputs.version }}-${{ github.run_number }} + name: Release ${{ steps.version.outputs.version }} (Build ${{ github.run_number }}) + body: | + ## 🚀 Deployed to Netlify + + - **Version:** ${{ steps.version.outputs.version }} + - **Build:** #${{ github.run_number }} + - **Commit:** [`${{ steps.changelog.outputs.short_sha }}`](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) + + 🌐 **[Launch Website →](${{ 'https://gear.dev/' }})** + + --- + + ### 📋 Changes + ${{ steps.changelog.outputs.changes }} + + ### 📊 Files Changed + ``` + ${{ steps.changelog.outputs.files_changed }} + ``` + + ### 🔍 Compare + ${{ steps.changelog.outputs.compare_url && format('- [**{0}** → **{1}** — View full diff]({2})', steps.changelog.outputs.previous_tag, format('{0}-{1}', steps.version.outputs.version, github.run_number), steps.changelog.outputs.compare_url) || '*(Initial release — no previous version to compare)*' }} + files: redact-check-build.zip + draft: false + prerelease: false