Skip to content

Commit

Permalink
Merge pull request #517 from blacklanternsecurity/change-tag-behavior
Browse files Browse the repository at this point in the history
Change tag behavior
  • Loading branch information
liquidsec authored Nov 8, 2024
2 parents 8968632 + e2c6d67 commit e025f1b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ updates:
directory: "/"
schedule:
interval: "daily"
target-branch: "main"
target-branch: "dev"
open-pull-requests-limit: 10
48 changes: 36 additions & 12 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
- name: flake8
run: |
flake8 --select F,E722 --ignore F403,F405,F541 --per-file-ignores="*/__init__.py:F401,F403"
test:
if: contains(github.event.pull_request.title, 'SignatureBot') == false
runs-on: ubuntu-latest
Expand Down Expand Up @@ -56,12 +57,11 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./cov.xml
verbose: true

publish:
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
continue-on-error: true
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -75,20 +75,44 @@ jobs:
python -m pip install --upgrade pip
pip install poetry build
poetry self add "poetry-dynamic-versioning[plugin]"
- name: Build Pypi package
if: github.ref == 'refs/heads/main'
- name: Get current version from Poetry
id: get_version
run: echo "VERSION=$(poetry version --short)" >> $GITHUB_ENV

- name: Fetch latest tag
run: |
git fetch --tags
LATEST_TAG=$(git describe --tags $(git rev-list --tags --max-count=1))
echo "LATEST_TAG=${LATEST_TAG}" >> $GITHUB_ENV
- name: Check for major or minor version change
id: check_major_minor_version
run: |
CURRENT_VERSION=${{ env.VERSION }}
LATEST_VERSION=${{ env.LATEST_TAG }}
# Extract major.minor for comparison
CURRENT_MAJOR_MINOR=$(echo $CURRENT_VERSION | cut -d '.' -f 1-2)
LATEST_MAJOR_MINOR=$(echo $LATEST_VERSION | cut -d '.' -f 1-2)
if [ "$CURRENT_MAJOR_MINOR" == "$LATEST_MAJOR_MINOR" ]; then
echo "VERSION_CHANGE=false" >> $GITHUB_ENV
else
echo "VERSION_CHANGE=true" >> $GITHUB_ENV
- name: Build PyPi package
if: github.ref == 'refs/heads/main' && env.VERSION_CHANGE == 'true'
run: python -m build
- name: Publish Pypi package
if: github.ref == 'refs/heads/main'

- name: Publish PyPi package
if: github.ref == 'refs/heads/main' && env.VERSION_CHANGE == 'true'
uses: pypa/gh-action-pypi-publish@release/v1.5
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Get current version from Poetry
id: get_version
run: echo "::set-output name=VERSION::$(poetry version --short)"
- name: Create Git tag

- name: Tag the release if major or minor version changed
if: github.ref == 'refs/heads/main' && env.VERSION_CHANGE == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "$(echo ${{ steps.get_version.outputs.VERSION }})" -m "Release ${{ steps.get_version.outputs.VERSION }}"
git push origin "$(echo ${{ steps.get_version.outputs.VERSION }})"
git tag -a "${{ env.VERSION }}" -m "Release ${{ env.VERSION }}"
git push origin "refs/tags/${{ env.VERSION }}"
14 changes: 7 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ httpx = "^0.27.2"
pyfakefs = "^5.2.3"
requests-mock = "^1.11.0"
pytest-cov = ">=5,<7"
pytest-asyncio = "^0.21.1"
pytest-asyncio = ">=0.21.1,<0.25.0"
mock = "^5.1.0"
pytest-mock = "^3.11.1"
poetry-dynamic-versioning = {extras = ["plugin"], version = "^1.2.0"}
Expand Down

0 comments on commit e025f1b

Please sign in to comment.