From c78ac61f3fb7fb04d2ddc07312755752013dc5fe Mon Sep 17 00:00:00 2001 From: Ryan Li Date: Fri, 7 Aug 2026 14:01:09 -0700 Subject: [PATCH 1/4] Add automation to drafting python release --- .github/workflows/draft-release.yml | 117 ++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 .github/workflows/draft-release.yml diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml new file mode 100644 index 0000000..e42c43b --- /dev/null +++ b/.github/workflows/draft-release.yml @@ -0,0 +1,117 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions. +# After doing that, it will draft a release with the most up to date version + +name: Draft release + +on: + workflow_dispatch: + inputs: + version: + description: 'Release version (must be in format .., e.g. 1.1.1)' + required: true + type: string + +permissions: + contents: write + +jobs: + build: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] + + steps: + - name: Verify inputs + env: + VERSION: ${{ inputs.version }} + run: | + SEMVER_REGEX="^([0-9]+)\.([0-9]+)\.([0-9]+)$" + if [[ ! "$VERSION" =~ $SEMVER_REGEX ]]; then + echo "::error::Invalid version format '$VERSION'. Must match X.Y.Z (e.g., 1.0.4)" + exit 1 + fi + + MAJOR="${BASH_REMATCH[1]}" + MINOR="${BASH_REMATCH[2]}" + PATCH="${BASH_REMATCH[3]}" + + # Latest released tag, newest first, ignoring anything not vX.Y.Z + LATEST_TAG=$(git ls-remote --tags --refs --sort=-v:refname \ + "https://github.com/${GITHUB_REPOSITORY}.git" \ + | sed 's#.*refs/tags/##' \ + | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \ + | head -n1) || true + + if [[ -z "$LATEST_TAG" ]]; then + echo "::error::No existing tag matching vX.Y.Z found" + exit 1 + fi + echo "Latest released tag: $LATEST_TAG" + + if [[ "$LATEST_TAG" == "v$VERSION" ]]; then + echo "::error::v$VERSION is already released" + exit 1 + fi + + [[ "${LATEST_TAG#v}" =~ $SEMVER_REGEX ]] + LATEST_MAJOR="${BASH_REMATCH[1]}" + LATEST_MINOR="${BASH_REMATCH[2]}" + LATEST_PATCH="${BASH_REMATCH[3]}" + + if [[ "$MAJOR" -eq "$LATEST_MAJOR" && "$MINOR" -eq "$LATEST_MINOR" && "$PATCH" -eq $((LATEST_PATCH + 1)) ]]; then + BUMP=patch + elif [[ "$MAJOR" -eq "$LATEST_MAJOR" && "$MINOR" -eq $((LATEST_MINOR + 1)) && "$PATCH" -eq 0 ]]; then + BUMP=minor + elif [[ "$MAJOR" -eq $((LATEST_MAJOR + 1)) && "$MINOR" -eq 0 && "$PATCH" -eq 0 ]]; then + BUMP=major + else + echo "::error::v$VERSION is not a valid bump from $LATEST_TAG" + exit 1 + fi + + echo "Releasing v$VERSION ($BUMP bump from $LATEST_TAG)" + + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt -r dev-requirements.txt + pip install -e . + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Lint with PyLint + run: pylint --rcfile=.pylintrc src/aws_secretsmanager_caching + - name: Check formatting with Ruff + uses: astral-sh/ruff-action@v3 + - name: Test with pytest + run: | + pytest test/unit/ + + draft-release: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Draft release v${{ inputs.version }} + env: + GH_TOKEN: ${{ github.token }} + VERSION: ${{ inputs.version }} + run: | + gh release create "v$VERSION" \ + --title "v$VERSION" \ + --generate-notes \ + --target "$GITHUB_SHA" + + echo "Drafted release v$VERSION" + gh release view "v$VERSION" --json url -q .url + \ No newline at end of file From b0b576d459686d121444078351c1b78d2cc31686 Mon Sep 17 00:00:00 2001 From: Ryan Li Date: Tue, 11 Aug 2026 15:23:20 -0700 Subject: [PATCH 2/4] Add call to PR workflow --- .github/workflows/draft-release.yml | 94 +++++++--------------------- .github/workflows/python-package.yml | 11 ++-- 2 files changed, 28 insertions(+), 77 deletions(-) diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index e42c43b..a1c415b 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -1,7 +1,7 @@ # This workflow will install Python dependencies, run tests and lint with a variety of Python versions. # After doing that, it will draft a release with the most up to date version -name: Draft release +name: Create New Release on: workflow_dispatch: @@ -11,19 +11,14 @@ on: required: true type: string -permissions: - contents: write - jobs: - build: + verify-input: runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] - + permissions: + contents: read steps: - - name: Verify inputs + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 + - name: Verify input env: VERSION: ${{ inputs.version }} run: | @@ -33,75 +28,31 @@ jobs: exit 1 fi - MAJOR="${BASH_REMATCH[1]}" - MINOR="${BASH_REMATCH[2]}" - PATCH="${BASH_REMATCH[3]}" + TAG="v$VERSION" - # Latest released tag, newest first, ignoring anything not vX.Y.Z - LATEST_TAG=$(git ls-remote --tags --refs --sort=-v:refname \ - "https://github.com/${GITHUB_REPOSITORY}.git" \ - | sed 's#.*refs/tags/##' \ - | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \ - | head -n1) || true - - if [[ -z "$LATEST_TAG" ]]; then - echo "::error::No existing tag matching vX.Y.Z found" + # Fail if the tag already exists + if git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then + echo "Error: Tag $TAG already exists. Aborting." exit 1 fi - echo "Latest released tag: $LATEST_TAG" - if [[ "$LATEST_TAG" == "v$VERSION" ]]; then - echo "::error::v$VERSION is already released" - exit 1 - fi - - [[ "${LATEST_TAG#v}" =~ $SEMVER_REGEX ]] - LATEST_MAJOR="${BASH_REMATCH[1]}" - LATEST_MINOR="${BASH_REMATCH[2]}" - LATEST_PATCH="${BASH_REMATCH[3]}" + echo "Creating Tag $TAG ..." - if [[ "$MAJOR" -eq "$LATEST_MAJOR" && "$MINOR" -eq "$LATEST_MINOR" && "$PATCH" -eq $((LATEST_PATCH + 1)) ]]; then - BUMP=patch - elif [[ "$MAJOR" -eq "$LATEST_MAJOR" && "$MINOR" -eq $((LATEST_MINOR + 1)) && "$PATCH" -eq 0 ]]; then - BUMP=minor - elif [[ "$MAJOR" -eq $((LATEST_MAJOR + 1)) && "$MINOR" -eq 0 && "$PATCH" -eq 0 ]]; then - BUMP=major - else - echo "::error::v$VERSION is not a valid bump from $LATEST_TAG" - exit 1 - fi - - echo "Releasing v$VERSION ($BUMP bump from $LATEST_TAG)" - - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt -r dev-requirements.txt - pip install -e . - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Lint with PyLint - run: pylint --rcfile=.pylintrc src/aws_secretsmanager_caching - - name: Check formatting with Ruff - uses: astral-sh/ruff-action@v3 - - name: Test with pytest - run: | - pytest test/unit/ + run-test: + permissions: + contents: read + id-token: write + needs: verify-input + uses: ./.github/workflows/python-package.yml draft-release: - needs: build + needs: run-test runs-on: ubuntu-latest + permissions: + contents: write + environment: release steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - name: Draft release v${{ inputs.version }} env: GH_TOKEN: ${{ github.token }} @@ -113,5 +64,4 @@ jobs: --target "$GITHUB_SHA" echo "Drafted release v$VERSION" - gh release view "v$VERSION" --json url -q .url \ No newline at end of file diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 80bd166..1a14316 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -8,6 +8,7 @@ on: branches: [master] pull_request: branches: [master] + workflow_call: permissions: contents: read @@ -22,9 +23,9 @@ jobs: python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 with: python-version: ${{ matrix.python-version }} - name: Install dependencies @@ -41,14 +42,14 @@ jobs: - name: Lint with PyLint run: pylint --rcfile=.pylintrc src/aws_secretsmanager_caching - name: Check formatting with Ruff - uses: astral-sh/ruff-action@v3 + uses: astral-sh/ruff-action@4919ec5cf1f49eff0871dbcea0da843445b837e6 with: version: "0.15.22" - name: Test with pytest run: | pytest test/unit/ - name: Upload coverage to Codecov - uses: codecov/codecov-action@v5 + uses: codecov/codecov-action@0fb7174895f61a3b6b78fc075e0cd60383518dac with: - fail_ci_if_error: true + fail_ci_if_error: false # REMEMBER TO FIX (SET LIKE THIS FOR TESTING) use_oidc: true From ccc682a83743e28cd96b584a730259310ab0f01c Mon Sep 17 00:00:00 2001 From: Ryan Li Date: Tue, 11 Aug 2026 15:30:07 -0700 Subject: [PATCH 3/4] test --- .github/workflows/draft-release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index a1c415b..0be6916 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -52,6 +52,7 @@ jobs: contents: write environment: release steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - name: Draft release v${{ inputs.version }} env: From 0c1fd5486a3a1a42b13814d2c10ad27492c7217f Mon Sep 17 00:00:00 2001 From: Ryan Li Date: Tue, 11 Aug 2026 15:37:27 -0700 Subject: [PATCH 4/4] test pr --- .github/workflows/draft-release.yml | 1 - .github/workflows/python-package.yml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/draft-release.yml b/.github/workflows/draft-release.yml index 0be6916..a1c415b 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/draft-release.yml @@ -52,7 +52,6 @@ jobs: contents: write environment: release steps: - - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 - name: Draft release v${{ inputs.version }} env: diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 1a14316..a09a978 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -51,5 +51,5 @@ jobs: - name: Upload coverage to Codecov uses: codecov/codecov-action@0fb7174895f61a3b6b78fc075e0cd60383518dac with: - fail_ci_if_error: false # REMEMBER TO FIX (SET LIKE THIS FOR TESTING) + fail_ci_if_error: false # REMEMBER TO FIX (SET LIKE THIS FOR TESTING) blah blah blah use_oidc: true