|
1 | | -name: Release |
| 1 | +# This is triggered manually. |
| 2 | +# This will bump the version and open a release pull request |
| 3 | +# Once the PR is accepted finish-release runs. |
| 4 | + |
2 | 5 |
|
3 | | -on: |
4 | | - push: |
5 | | - branches: |
6 | | - - main |
| 6 | +name: Release |
7 | 7 |
|
| 8 | +on: |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + SemVer_level: |
| 12 | + type: choice |
| 13 | + description: Which SemVer to bump |
| 14 | + options: |
| 15 | + - major |
| 16 | + - minor |
| 17 | + - patch |
| 18 | + default: patch |
| 19 | + SemVer_version: |
| 20 | + type: string |
| 21 | + description: "Specify an exact version (leave empty to auto-bump)" |
| 22 | + default: "" |
| 23 | + |
8 | 24 | jobs: |
9 | | - release: |
| 25 | + create_release_branch: |
10 | 26 | runs-on: ubuntu-latest |
11 | 27 | steps: |
12 | | - - name: Checkout Repository |
13 | | - uses: actions/checkout@v4 |
14 | | - with: |
15 | | - fetch-depth: 0 # Required for versioning |
16 | | - |
17 | | - - name: Set up Python |
18 | | - uses: actions/setup-python@v5 |
19 | | - with: |
20 | | - python-version: "3.10" |
21 | | - |
22 | | - - name: Install Poetry |
23 | | - run: pip install poetry |
24 | | - |
25 | | - - name: Install Dependencies |
26 | | - run: poetry install |
27 | | - |
28 | | - - name: Run Tests |
29 | | - run: poetry run pytest # Adjust if needed |
30 | | - |
31 | | - - name: Bump Version |
32 | | - id: bump_version |
33 | | - run: | |
34 | | - poetry version patch # Change to minor/major if needed |
35 | | - echo "VERSION=$(poetry version -s)" >> $GITHUB_ENV |
36 | | -
|
37 | | - - name: Commit & Tag New Version |
38 | | - run: | |
39 | | - git config --global user.name "GitHub Actions" |
40 | | - git config --global user.email "actions@github.com" |
41 | | - git add pyproject.toml |
42 | | - git commit -m "chore(release): bump version to $VERSION" |
43 | | - git tag "v$VERSION" |
44 | | - git push origin main --tags |
45 | | -
|
46 | | - - name: Create GitHub Release |
47 | | - uses: softprops/action-gh-release@v2 |
48 | | - with: |
49 | | - tag_name: v${{ env.VERSION }} |
50 | | - name: Release v${{ env.VERSION }} |
51 | | - draft: true |
52 | | - prerelease: false |
53 | | - generate_release_notes: true |
54 | | - |
55 | | - - name: Publish to PyPI |
56 | | - env: |
57 | | - POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_API_TOKEN }} |
58 | | - run: poetry publish --build |
| 28 | + - name: Checkout Repository |
| 29 | + uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + fetch-depth: 0 |
| 32 | + |
| 33 | + - name: Set up Python |
| 34 | + uses: actions/setup-python@v5 |
| 35 | + with: |
| 36 | + python-version: '3.10' |
| 37 | + |
| 38 | + - name: Install poetry |
| 39 | + run: pip install poetry |
| 40 | + |
| 41 | + - name: Install dependencies |
| 42 | + run: poetry install |
| 43 | + |
| 44 | + - name: Determine Version |
| 45 | + id: determine_version |
| 46 | + run: | |
| 47 | + if [ -n "${{ github.event.inputs.SemVer_version }}" ]; then |
| 48 | + VERSION=${{ github.event.inputs.SemVer_version }} |
| 49 | + poetry version "$VERSION" |
| 50 | + else |
| 51 | + poetry version ${{ github.event.inputs.SemVer_level }} |
| 52 | + VERSION=$(poetry version -s) |
| 53 | + fi |
| 54 | + sed -i "s/cloudgoat.version=\".*\"/cloudgoat.version=\"$VERSION\"/" Dockerfile |
| 55 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 56 | + echo "::set-output name=VERSION::$VERSION" |
| 57 | +
|
| 58 | + - name: Create Release Branch |
| 59 | + run: | |
| 60 | + git checkout -b release-v${{ env.VERSION }} |
| 61 | +
|
| 62 | + - name: Commit Version Change |
| 63 | + run: | |
| 64 | + git config --global user.name "GitHub Actions" |
| 65 | + git config --global user.email "actions@github.com" |
| 66 | + git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git |
| 67 | + git add . |
| 68 | + git commit -m "chore(release): bump version to ${VERSION}" |
| 69 | + git push origin release-v${{ env.VERSION }} |
| 70 | +
|
| 71 | + - name: Create Pull Request via CLI |
| 72 | + run: | |
| 73 | + gh auth login --with-token <<< "${{ secrets.GITHUB_TOKEN }}" |
| 74 | + gh pr create \ |
| 75 | + --base master \ |
| 76 | + --head release-v${{ env.VERSION }} \ |
| 77 | + --title "Release v${{ env.VERSION }}" \ |
| 78 | + --body "Automated release PR for version v${{ env.VERSION }}" \ |
| 79 | + --draft=false |
| 80 | + env: |
| 81 | + GH_PAT: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + GH_REPO: ${{ github.repository }} |
0 commit comments