|
5 | 5 | branches: |
6 | 6 | - main |
7 | 7 |
|
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + pull-requests: write |
| 11 | + |
8 | 12 | jobs: |
9 | 13 | validate-commits: |
10 | 14 | runs-on: ubuntu-latest |
|
54 | 58 |
|
55 | 59 | - name: Run tests |
56 | 60 | run: just test |
| 61 | + |
| 62 | + release-preview: |
| 63 | + runs-on: ubuntu-latest |
| 64 | + needs: [validate-commits, lint-and-test] |
| 65 | + if: github.event_name == 'pull_request' |
| 66 | + |
| 67 | + steps: |
| 68 | + - name: Checkout Repository |
| 69 | + uses: actions/checkout@v4 |
| 70 | + with: |
| 71 | + fetch-depth: 0 |
| 72 | + |
| 73 | + - name: Setup Python |
| 74 | + uses: actions/setup-python@v5 |
| 75 | + with: |
| 76 | + python-version: "3.12" |
| 77 | + |
| 78 | + - name: Install uv |
| 79 | + uses: astral-sh/setup-uv@v4 |
| 80 | + |
| 81 | + - name: Install just |
| 82 | + uses: extractions/setup-just@v2 |
| 83 | + |
| 84 | + - name: Install dependencies |
| 85 | + run: uv sync --all-extras |
| 86 | + |
| 87 | + - name: Generate release preview |
| 88 | + id: release-preview |
| 89 | + run: | |
| 90 | + # Get version preview information using the Python script |
| 91 | + version_preview=$(uv run python scripts/version_preview.py --format github-summary) |
| 92 | + |
| 93 | + echo "preview<<EOF" >> $GITHUB_OUTPUT |
| 94 | + echo "$version_preview" >> $GITHUB_OUTPUT |
| 95 | + echo "EOF" >> $GITHUB_OUTPUT |
| 96 | + |
| 97 | + # Check if there are any changes by looking for version information |
| 98 | + changes=$(uv run python scripts/version_preview.py --format json) |
| 99 | + if [ "$changes" = "[]" ] || [ -z "$changes" ]; then |
| 100 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 101 | + else |
| 102 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 103 | + fi |
| 104 | +
|
| 105 | + - name: Display release preview |
| 106 | + if: steps.release-preview.outputs.has_changes == 'true' |
| 107 | + run: | |
| 108 | + # Use cat with here document to safely handle special characters |
| 109 | + cat >> $GITHUB_STEP_SUMMARY << 'EOF' |
| 110 | + ${{ steps.release-preview.outputs.preview }} |
| 111 | + |
| 112 | + ### 📝 Changelog Preview |
| 113 | + |
| 114 | + ``` |
| 115 | + EOF |
| 116 | + just preview-changelog >> $GITHUB_STEP_SUMMARY |
| 117 | + echo '```' >> $GITHUB_STEP_SUMMARY |
| 118 | +
|
| 119 | + - name: No release preview |
| 120 | + if: steps.release-preview.outputs.has_changes == 'false' |
| 121 | + run: | |
| 122 | + # Use cat with here document to safely handle special characters |
| 123 | + cat >> $GITHUB_STEP_SUMMARY << 'EOF' |
| 124 | + ${{ steps.release-preview.outputs.preview }} |
| 125 | + EOF |
| 126 | +
|
| 127 | + - name: Comment on PR with release preview |
| 128 | + if: github.event_name == 'pull_request' |
| 129 | + env: |
| 130 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 131 | + GH_REPO: ${{ github.repository }} |
| 132 | + PR_NUMBER: ${{ github.event.number }} |
| 133 | + run: | |
| 134 | + uv run python scripts/pr_comment.py |
0 commit comments