|
8 | 8 | permissions: |
9 | 9 | contents: write |
10 | 10 |
|
| 11 | +concurrency: |
| 12 | + group: release-${{ github.ref }} |
| 13 | + cancel-in-progress: false |
| 14 | + |
11 | 15 | jobs: |
12 | 16 | build-n-publish: |
13 | | - if: github.event.base_ref == 'refs/heads/main' || github.event.base_ref == 'refs/heads/master' |
14 | 17 | name: Publish to PyPI |
15 | 18 | runs-on: ubuntu-latest |
16 | 19 |
|
|
25 | 28 | # https://github.com/actions/checkout/issues/338 |
26 | 29 | fetch-depth: 0 |
27 | 30 |
|
| 31 | + - name: Verify tag is from master branch |
| 32 | + run: | |
| 33 | + echo "Verifying that tag ${{ github.ref_name }} was created from main/master branch..." |
| 34 | +
|
| 35 | + # Get all remote branches containing this commit |
| 36 | + BRANCHES=$(git branch -r --contains ${{ github.sha }} | sed 's/^[[:space:]]*//') |
| 37 | +
|
| 38 | + echo "Branches containing commit ${{ github.sha }}:" |
| 39 | + echo "$BRANCHES" |
| 40 | +
|
| 41 | + # Check if main or master is in the list |
| 42 | + if ! echo "$BRANCHES" | grep -qE 'origin/(main|master)$'; then |
| 43 | + echo "" |
| 44 | + echo "❌ ERROR: Tag ${{ github.ref_name }} was not created from main/master branch" |
| 45 | + echo "This is a security measure to prevent releases from feature branches." |
| 46 | + echo "" |
| 47 | + echo "To fix this:" |
| 48 | + echo "1. Checkout main/master branch: git checkout master" |
| 49 | + echo "2. Create tag from main/master: git tag ${{ github.ref_name }}" |
| 50 | + echo "3. Delete the incorrect tag: git push --delete origin ${{ github.ref_name }}" |
| 51 | + echo "4. Push the correct tag: git push origin ${{ github.ref_name }}" |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | +
|
| 55 | + echo "✅ Verified: Tag was created from main/master branch" |
| 56 | +
|
28 | 57 | - name: Setup Java |
29 | 58 | uses: actions/setup-java@v4 |
30 | 59 | with: |
|
40 | 69 | uses: actions/setup-python@v5 |
41 | 70 | with: |
42 | 71 | python-version: "3.10" |
| 72 | + cache: 'pip' |
43 | 73 |
|
44 | 74 | - name: Install dependencies and package |
45 | 75 | run: | |
|
68 | 98 | repository-url: https://test.pypi.org/legacy/ |
69 | 99 |
|
70 | 100 | - name: Publish distribution 📦 to PyPI |
71 | | - if: startsWith(github.ref, 'refs/tags') |
72 | 101 | uses: pypa/gh-action-pypi-publish@release/v1 |
73 | 102 | with: |
74 | 103 | password: ${{ secrets.PYPI_API_TOKEN }} |
|
0 commit comments