|
| 1 | +name: Weekly Auto Release |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Every Monday at 00:00 UTC |
| 6 | + - cron: '0 0 * * 1' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + id-token: write |
| 12 | + pull-requests: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + weekly-release: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + name: Auto Version & Release |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + |
| 26 | + - name: Setup Node.js |
| 27 | + uses: actions/setup-node@v4 |
| 28 | + with: |
| 29 | + node-version: '20' |
| 30 | + registry-url: 'https://registry.npmjs.org' |
| 31 | + |
| 32 | + - name: Configure Git |
| 33 | + run: | |
| 34 | + git config user.name "github-actions[bot]" |
| 35 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 36 | +
|
| 37 | + - name: Install dependencies |
| 38 | + run: npm ci |
| 39 | + |
| 40 | + - name: Build package |
| 41 | + run: npm run build |
| 42 | + |
| 43 | + - name: Check if there are changes |
| 44 | + id: changes |
| 45 | + run: | |
| 46 | + if git diff-index --quiet HEAD --; then |
| 47 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 48 | + else |
| 49 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: Get current version |
| 53 | + id: current_version |
| 54 | + run: | |
| 55 | + CURRENT_VERSION=$(node -e "console.log(require('./package.json').version)") |
| 56 | + echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT |
| 57 | +
|
| 58 | + - name: Calculate new version |
| 59 | + id: new_version |
| 60 | + run: | |
| 61 | + CURRENT_VERSION="${{ steps.current_version.outputs.version }}" |
| 62 | + MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1) |
| 63 | + MINOR=$(echo $CURRENT_VERSION | cut -d. -f2) |
| 64 | + PATCH=$(echo $CURRENT_VERSION | cut -d. -f3) |
| 65 | + NEW_PATCH=$((PATCH + 1)) |
| 66 | + NEW_VERSION="$MAJOR.$MINOR.$NEW_PATCH" |
| 67 | + echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT |
| 68 | + echo "New version: $NEW_VERSION" |
| 69 | +
|
| 70 | + - name: Update version in package.json |
| 71 | + run: | |
| 72 | + npm version ${{ steps.new_version.outputs.version }} --no-git-tag-version |
| 73 | + echo "Updated package.json to version ${{ steps.new_version.outputs.version }}" |
| 74 | +
|
| 75 | + - name: Update version in package-lock.json |
| 76 | + run: | |
| 77 | + npm ci |
| 78 | +
|
| 79 | + - name: Create commit and tag |
| 80 | + run: | |
| 81 | + git add package.json package-lock.json |
| 82 | + git commit -m "chore: bump version to ${{ steps.new_version.outputs.version }}" |
| 83 | + git tag -a v${{ steps.new_version.outputs.version }} -m "Release v${{ steps.new_version.outputs.version }}" |
| 84 | + echo "✅ Created tag: v${{ steps.new_version.outputs.version }}" |
| 85 | +
|
| 86 | + - name: Push changes and tags |
| 87 | + run: | |
| 88 | + git push origin main |
| 89 | + git push origin v${{ steps.new_version.outputs.version }} |
| 90 | + echo "✅ Pushed to GitHub" |
| 91 | +
|
| 92 | + - name: Create GitHub Release |
| 93 | + uses: actions/create-release@v1 |
| 94 | + env: |
| 95 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 96 | + with: |
| 97 | + tag_name: v${{ steps.new_version.outputs.version }} |
| 98 | + release_name: Release v${{ steps.new_version.outputs.version }} |
| 99 | + body: | |
| 100 | + # 📦 Weekly Release - v${{ steps.new_version.outputs.version }} |
| 101 | +
|
| 102 | + **Date**: ${{ github.event.scheduled_time || 'Manual Release' }} |
| 103 | +
|
| 104 | + ## Changes |
| 105 | + - Auto-bumped patch version |
| 106 | + - Rebuilt package |
| 107 | + - Published with NPM Provenance |
| 108 | +
|
| 109 | + ## Installation |
| 110 | + ```bash |
| 111 | + npm install @hixbe/time@${{ steps.new_version.outputs.version }} |
| 112 | + ``` |
| 113 | +
|
| 114 | + ## Quick Start |
| 115 | + ```bash |
| 116 | + npx hixbe-time |
| 117 | + ``` |
| 118 | +
|
| 119 | + --- |
| 120 | + This release was automatically created by GitHub Actions. |
| 121 | + Package security verified with [NPM Provenance](https://docs.npmjs.com/about-npm-provenance). |
| 122 | + draft: false |
| 123 | + prerelease: false |
| 124 | + |
| 125 | + - name: Publish to NPM |
| 126 | + run: npm publish --provenance |
| 127 | + env: |
| 128 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 129 | + |
| 130 | + - name: Release Success Summary |
| 131 | + run: | |
| 132 | + echo "═══════════════════════════════════════════════════════════" |
| 133 | + echo "✅ WEEKLY RELEASE SUCCESSFUL" |
| 134 | + echo "═══════════════════════════════════════════════════════════" |
| 135 | + echo "" |
| 136 | + echo "📦 Package: @hixbe/time" |
| 137 | + echo "🏷️ Version: v${{ steps.new_version.outputs.version }}" |
| 138 | + echo "🔄 Previous: v${{ steps.current_version.outputs.version }}" |
| 139 | + echo "" |
| 140 | + echo "📝 Changes:" |
| 141 | + echo " • Patch version auto-bumped" |
| 142 | + echo " • Git tag created: v${{ steps.new_version.outputs.version }}" |
| 143 | + echo " • GitHub Release published" |
| 144 | + echo " • NPM published with provenance" |
| 145 | + echo "" |
| 146 | + echo "🔗 Links:" |
| 147 | + echo " • NPM: https://www.npmjs.com/package/@hixbe/time" |
| 148 | + echo " • GitHub: https://github.com/${{ github.repository }}/releases/tag/v${{ steps.new_version.outputs.version }}" |
| 149 | + echo "" |
| 150 | + echo "═══════════════════════════════════════════════════════════" |
| 151 | +
|
| 152 | + - name: Notify on Failure |
| 153 | + if: failure() |
| 154 | + run: | |
| 155 | + echo "❌ Weekly release failed" |
| 156 | + echo "Check the logs for details" |
| 157 | + exit 1 |
0 commit comments