11# This workflow will install Python dependencies, run tests and lint with a variety of Python versions.
22# After doing that, it will draft a release with the most up to date version
33
4- name : Draft release
4+ name : Create New Release
55
66on :
77 workflow_dispatch :
1111 required : true
1212 type : string
1313
14- permissions :
15- contents : write
16-
1714jobs :
18- build :
15+ verify-input :
1916 runs-on : ubuntu-latest
20- strategy :
21- fail-fast : false
22- matrix :
23- python-version : ["3.9", "3.10", "3.11", "3.12", "3.13"]
24-
17+ permissions :
18+ contents : read
2519 steps :
26- - name : Verify inputs
20+ - uses : actions/checkout@11d5960a326750d5838078e36cf38b85af677262
21+ - name : Verify input
2722 env :
2823 VERSION : ${{ inputs.version }}
2924 run : |
@@ -33,75 +28,31 @@ jobs:
3328 exit 1
3429 fi
3530
36- MAJOR="${BASH_REMATCH[1]}"
37- MINOR="${BASH_REMATCH[2]}"
38- PATCH="${BASH_REMATCH[3]}"
31+ TAG="v$VERSION"
3932
40- # Latest released tag, newest first, ignoring anything not vX.Y.Z
41- LATEST_TAG=$(git ls-remote --tags --refs --sort=-v:refname \
42- "https://github.com/${GITHUB_REPOSITORY}.git" \
43- | sed 's#.*refs/tags/##' \
44- | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
45- | head -n1) || true
46-
47- if [[ -z "$LATEST_TAG" ]]; then
48- echo "::error::No existing tag matching vX.Y.Z found"
33+ # Fail if the tag already exists
34+ if git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then
35+ echo "Error: Tag $TAG already exists. Aborting."
4936 exit 1
5037 fi
51- echo "Latest released tag: $LATEST_TAG"
5238
53- if [[ "$LATEST_TAG" == "v$VERSION" ]]; then
54- echo "::error::v$VERSION is already released"
55- exit 1
56- fi
57-
58- [[ "${LATEST_TAG#v}" =~ $SEMVER_REGEX ]]
59- LATEST_MAJOR="${BASH_REMATCH[1]}"
60- LATEST_MINOR="${BASH_REMATCH[2]}"
61- LATEST_PATCH="${BASH_REMATCH[3]}"
39+ echo "Creating Tag $TAG ..."
6240
63- if [[ "$MAJOR" -eq "$LATEST_MAJOR" && "$MINOR" -eq "$LATEST_MINOR" && "$PATCH" -eq $((LATEST_PATCH + 1)) ]]; then
64- BUMP=patch
65- elif [[ "$MAJOR" -eq "$LATEST_MAJOR" && "$MINOR" -eq $((LATEST_MINOR + 1)) && "$PATCH" -eq 0 ]]; then
66- BUMP=minor
67- elif [[ "$MAJOR" -eq $((LATEST_MAJOR + 1)) && "$MINOR" -eq 0 && "$PATCH" -eq 0 ]]; then
68- BUMP=major
69- else
70- echo "::error::v$VERSION is not a valid bump from $LATEST_TAG"
71- exit 1
72- fi
73-
74- echo "Releasing v$VERSION ($BUMP bump from $LATEST_TAG)"
75-
76- - uses : actions/checkout@v4
77- - name : Set up Python ${{ matrix.python-version }}
78- uses : actions/setup-python@v5
79- with :
80- python-version : ${{ matrix.python-version }}
81- - name : Install dependencies
82- run : |
83- python -m pip install --upgrade pip
84- pip install -r requirements.txt -r dev-requirements.txt
85- pip install -e .
86- - name : Lint with flake8
87- run : |
88- # stop the build if there are Python syntax errors or undefined names
89- flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
90- # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
91- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
92- - name : Lint with PyLint
93- run : pylint --rcfile=.pylintrc src/aws_secretsmanager_caching
94- - name : Check formatting with Ruff
95- uses : astral-sh/ruff-action@v3
96- - name : Test with pytest
97- run : |
98- pytest test/unit/
41+ run-test :
42+ permissions :
43+ contents : read
44+ id-token : write
45+ needs : verify-input
46+ uses : ./.github/workflows/python-package.yml
9947
10048 draft-release :
101- needs : build
49+ needs : run-test
10250 runs-on : ubuntu-latest
51+ permissions :
52+ contents : write
53+ environment : release
10354 steps :
104- - uses : actions/checkout@v4
55+ - uses : actions/checkout@11d5960a326750d5838078e36cf38b85af677262
10556 - name : Draft release v${{ inputs.version }}
10657 env :
10758 GH_TOKEN : ${{ github.token }}
11364 --target "$GITHUB_SHA"
11465
11566 echo "Drafted release v$VERSION"
116- gh release view "v$VERSION" --json url -q .url
11767
0 commit comments