|
| 1 | +name: Cut Release |
| 2 | +on: |
| 3 | + workflow_dispatch: {} |
| 4 | + |
| 5 | +permissions: |
| 6 | + contents: write |
| 7 | + pull-requests: write |
| 8 | + |
| 9 | +jobs: |
| 10 | + release: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 14 | + with: |
| 15 | + persist-credentials: true |
| 16 | + fetch-tags: true |
| 17 | + fetch-depth: 0 |
| 18 | + token: ${{ secrets.WRITE_GH_TOKEN }} |
| 19 | + |
| 20 | + - uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0 |
| 21 | + with: |
| 22 | + node-version: "latest" # does not matter for our needs |
| 23 | + |
| 24 | + - uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0 |
| 25 | + with: |
| 26 | + go-version: "stable" |
| 27 | + |
| 28 | + - name: Setup Git |
| 29 | + run: | |
| 30 | + git config user.name "github-actions[bot]" |
| 31 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 32 | +
|
| 33 | + - name: Create release branch and run semantic-release |
| 34 | + env: |
| 35 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 36 | + run: | |
| 37 | + npm ci |
| 38 | +
|
| 39 | + # Create a unique release branch |
| 40 | + TIMESTAMP=$(date +%s) |
| 41 | + BRANCH_NAME="release-${TIMESTAMP}" |
| 42 | +
|
| 43 | + # Create and checkout release branch |
| 44 | + git checkout -b "${BRANCH_NAME}" |
| 45 | +
|
| 46 | + # Run semantic-release on the release branch |
| 47 | + npx semantic-release --debug |
| 48 | +
|
| 49 | + # Check if semantic-release made changes |
| 50 | + if git diff --quiet origin/main HEAD 2>/dev/null || [ $(git rev-list --count HEAD ^origin/main) -eq 0 ]; then |
| 51 | + echo "No release created" |
| 52 | + exit 0 |
| 53 | + fi |
| 54 | +
|
| 55 | + # Push the release branch |
| 56 | + git push origin "${BRANCH_NAME}" |
| 57 | +
|
| 58 | + # Get the version from the commit message or package.json |
| 59 | + VERSION=$(node -p "require('./package.json').version" 2>/dev/null || echo "unknown") |
| 60 | +
|
| 61 | + # Create pull request |
| 62 | + gh pr create \ |
| 63 | + --title "chore(release): ${VERSION}" \ |
| 64 | + --body "Automated release PR for version ${VERSION}. This PR includes updates to CHANGELOG.md and package.json. Once this PR is merged to main, the GitHub release will be created automatically." \ |
| 65 | + --base main \ |
| 66 | + --head "${BRANCH_NAME}" \ |
| 67 | + --label "release" |
| 68 | +
|
| 69 | + - name: Clean up old release branches |
| 70 | + if: always() |
| 71 | + env: |
| 72 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 73 | + run: | |
| 74 | + # Get all release branches except the current one |
| 75 | + for branch in $(git ls-remote --heads origin "release-*" | awk '{print $2}' | sed 's|refs/heads/||' | grep -v "^${BRANCH_NAME}$"); do |
| 76 | + echo "Deleting old release branch: ${branch}" |
| 77 | + git push origin --delete "${branch}" || true |
| 78 | + done |
0 commit comments