|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + name: Release |
| 11 | + runs-on: ubuntu-latest |
| 12 | + permissions: write-all |
| 13 | + outputs: |
| 14 | + bumped: ${{ steps.release.outputs.bumped }} |
| 15 | + bump_version: ${{ steps.release.outputs.bump_version }} |
| 16 | + bump_sha: ${{ steps.release.outputs.bump_sha }} |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + with: |
| 20 | + ref: master |
| 21 | + fetch-depth: 0 |
| 22 | + |
| 23 | + - name: Verify commit came from a PR with passing checks |
| 24 | + id: verify |
| 25 | + env: |
| 26 | + GH_TOKEN: ${{ github.token }} |
| 27 | + run: | |
| 28 | + echo "🔍 Checking if commit ${{ github.sha }} came from a valid PR..." |
| 29 | + for i in 1 2 3; do |
| 30 | + PR_JSON=$(gh api repos/${{ github.repository }}/commits/${{ github.sha }}/pulls 2>/dev/null || echo "[]") |
| 31 | + PR_COUNT=$(echo "$PR_JSON" | jq 'length') |
| 32 | + if [ "$PR_COUNT" -gt 0 ]; then |
| 33 | + break |
| 34 | + fi |
| 35 | + echo " Attempt $i: No PR found yet, waiting 2s..." |
| 36 | + sleep 2 |
| 37 | + done |
| 38 | +
|
| 39 | + if [ "$PR_COUNT" -eq 0 ]; then |
| 40 | + echo "❌ This commit did not come from a PR - skipping release" |
| 41 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 42 | + exit 0 |
| 43 | + fi |
| 44 | +
|
| 45 | + PR_NUMBER=$(echo "$PR_JSON" | jq -r '.[0].number') |
| 46 | + HEAD_SHA=$(echo "$PR_JSON" | jq -r '.[0].head.sha') |
| 47 | + PR_TITLE=$(echo "$PR_JSON" | jq -r '.[0].title') |
| 48 | + echo "📋 Found PR #$PR_NUMBER: $PR_TITLE" |
| 49 | +
|
| 50 | + REQUIRED_CHECKS=("Lint" "Security" "Coverage") |
| 51 | + ALL_PASSED=true |
| 52 | + for CHECK_NAME in "${REQUIRED_CHECKS[@]}"; do |
| 53 | + RESULT=$(gh api repos/${{ github.repository }}/commits/$HEAD_SHA/check-runs \ |
| 54 | + --jq ".check_runs[] | select(.name == \"$CHECK_NAME\") | .conclusion" 2>/dev/null | head -1) |
| 55 | + if [ "$RESULT" = "success" ]; then |
| 56 | + echo " ✅ $CHECK_NAME: passed" |
| 57 | + else |
| 58 | + echo " ❌ $CHECK_NAME: $RESULT" |
| 59 | + ALL_PASSED=false |
| 60 | + fi |
| 61 | + done |
| 62 | +
|
| 63 | + if [ "$ALL_PASSED" = "false" ]; then |
| 64 | + echo "❌ Required checks did not pass - skipping release" |
| 65 | + echo "should_release=false" >> $GITHUB_OUTPUT |
| 66 | + exit 0 |
| 67 | + fi |
| 68 | +
|
| 69 | + echo "✅ All required checks passed on PR #$PR_NUMBER" |
| 70 | + echo "should_release=true" >> $GITHUB_OUTPUT |
| 71 | + echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT |
| 72 | +
|
| 73 | + - name: Skip release notification |
| 74 | + if: steps.verify.outputs.should_release != 'true' |
| 75 | + run: | |
| 76 | + echo "⚠️ Release skipped - commit did not meet release criteria" |
| 77 | +
|
| 78 | + - uses: actions/setup-python@v5 |
| 79 | + if: steps.verify.outputs.should_release == 'true' |
| 80 | + with: |
| 81 | + python-version: "3.13" |
| 82 | + |
| 83 | + - name: Install dependencies |
| 84 | + if: steps.verify.outputs.should_release == 'true' |
| 85 | + run: | |
| 86 | + pip install git+https://${{ secrets.ORGANIZATIONAL_REPO_TOKEN }}@github.com/pivotal-energy-solutions/tensor-infrastructure@master#egg=infrastructure |
| 87 | +
|
| 88 | + - name: Release |
| 89 | + id: release |
| 90 | + if: steps.verify.outputs.should_release == 'true' |
| 91 | + env: |
| 92 | + PYTHONWARNINGS: once::DeprecationWarning |
| 93 | + GITHUB_TOKEN: ${{ secrets.ORGANIZATIONAL_REPO_TOKEN }} |
| 94 | + GH_TOKEN: ${{ github.token }} |
| 95 | + run: | |
| 96 | + echo "🚀 Creating release for PR #${{ steps.verify.outputs.pr_number }}..." |
| 97 | + bumper -P |
| 98 | + echo "bumped=$(jq '.bumped' out.json)" >> $GITHUB_OUTPUT |
| 99 | + echo "bump_version=$(jq '.bump_version' out.json)" >> $GITHUB_OUTPUT |
| 100 | + echo "bump_sha=$(jq '.bump_sha' out.json)" >> $GITHUB_OUTPUT |
| 101 | +
|
| 102 | + VERSION=$(jq -r '.bump_version' out.json) |
| 103 | + BUMPED=$(jq -r '.bumped' out.json) |
| 104 | +
|
| 105 | + if [ "$BUMPED" = "true" ]; then |
| 106 | + PR_INFO=$(gh api repos/${{ github.repository }}/pulls/${{ steps.verify.outputs.pr_number }} --jq '{title: .title, user: .user.login, html_url: .html_url}') |
| 107 | + PR_TITLE=$(echo "$PR_INFO" | jq -r '.title') |
| 108 | + PR_AUTHOR=$(echo "$PR_INFO" | jq -r '.user') |
| 109 | + PR_URL=$(echo "$PR_INFO" | jq -r '.html_url') |
| 110 | +
|
| 111 | + cat >> $GITHUB_STEP_SUMMARY << EOF |
| 112 | + ## 🚀 Release $VERSION |
| 113 | +
|
| 114 | + | | | |
| 115 | + |---|---| |
| 116 | + | **Version** | \`$VERSION\` | |
| 117 | + | **PR** | [#${{ steps.verify.outputs.pr_number }}]($PR_URL) | |
| 118 | + | **Title** | $PR_TITLE | |
| 119 | + | **Author** | @$PR_AUTHOR | |
| 120 | + | **Commit** | \`${{ github.sha }}\` | |
| 121 | +
|
| 122 | + ### Release Assets |
| 123 | + - 📦 [View Release](https://github.com/${{ github.repository }}/releases/tag/$VERSION) |
| 124 | + - 🏷️ Tag: \`$VERSION\` |
| 125 | + EOF |
| 126 | + fi |
0 commit comments