diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..cbd920f --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/pr-lint.yml b/.github/workflows/pr-lint.yml index dc7af3d..5bbede7 100644 --- a/.github/workflows/pr-lint.yml +++ b/.github/workflows/pr-lint.yml @@ -3,13 +3,22 @@ on: pull_request_target: types: [ opened, edited, synchronize, reopened ] +permissions: + contents: read + pull-requests: read + jobs: validate: name: Validate title - runs-on: ubuntu-latest + runs-on: ubuntu-x64 steps: - - uses: amannn/action-semantic-pull-request@v4 + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + - uses: twilio/sdk-actions/semantic-pr-title@09631bfa50f14d276170d45bc4f49a80da201cc6 # main @ 09631bf — sdk-actions#10; repin to the v1.1.0 tag once cut with: - types: chore docs fix feat test - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + types: | + chore + docs + fix + feat + misc + test diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index a20234e..68aa231 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -10,71 +10,119 @@ on: - cron: '0 15 * * 1-5' workflow_dispatch: +env: + ARTIFACTORY_URL: ${{ vars.ARTIFACTORY_URL }} + jobs: test: - name: Test - runs-on: ubuntu-latest + name: Test - Python ${{ matrix.python-version }} + runs-on: ubuntu-x64 + if: github.repository_owner == 'sendgrid' timeout-minutes: 20 + permissions: + contents: read + id-token: write strategy: + fail-fast: false matrix: - python-version: [ '2.7', '3.5', '3.6', '3.7', '3.8', '3.9', '3.10' ] + python-version: [ '3.9', '3.10', '3.11', '3.12', '3.13' ] steps: - - name: Checkout sendgrid-python-http-client - uses: actions/checkout@v2 + - name: Checkout python-http-client + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + + - name: Artifactory OIDC Auth + uses: twilio/sdk-actions/artifactory-oidc@0375437914d535a5fb178bdbfdb5d51bdde2616e # v1 + with: + ecosystem: python - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 with: python-version: ${{ matrix.python-version }} - name: Build & Test run: make install test-install test + deploy: name: Deploy - if: success() && github.ref_type == 'tag' + if: success() && github.ref_type == 'tag' && github.repository_owner == 'sendgrid' needs: [ test ] - runs-on: ubuntu-latest + runs-on: ubuntu-x64 + environment: + name: production + url: https://pypi.org/project/python_http_client/${{ github.ref_name }} + permissions: + contents: write # required for creating GitHub Release + id-token: write + attestations: write steps: - - name: Checkout sendgrid-python-http-client - uses: actions/checkout@v2 + - name: Checkout python-http-client + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + with: + # The release action verifies refs/tags/ in the local clone. + fetch-depth: 0 + + - name: Artifactory OIDC Auth + uses: twilio/sdk-actions/artifactory-oidc@0375437914d535a5fb178bdbfdb5d51bdde2616e # v1 + with: + ecosystem: python - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5 with: - python-version: '3.10' + python-version: '3.12' + + - name: Validate tag format and version match + run: | + pip install setuptools + TAG="${GITHUB_REF#refs/tags/}" + VERSION="${TAG#v}" + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+ ]]; then + echo "::error::Release tag must look like 1.2.3 or v1.2.3 (got '$TAG')" + exit 1 + fi + PKG_VERSION=$(python setup.py --version) + if [ "$VERSION" != "$PKG_VERSION" ]; then + echo "::error::Tag $TAG does not match setup.py version $PKG_VERSION" + exit 1 + fi - - name: Install dependencies + - name: Build package run: | - python -m pip install --upgrade pip - pip install build - pip install wheel - python setup.py sdist bdist_wheel + pip install build twine + python -m build + twine check dist/* - - name: Publish package to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 + - name: Create GitHub Release + uses: twilio/sdk-actions/github-release@9b1c3222c9ffe38aadedb11c5b9f5a172b5e9951 # v1 with: - user: __token__ - password: ${{ secrets.PYPI_TOKEN }} + changelog-file: CHANGELOG.md + footer: '**[PyPI](https://pypi.org/project/python_http_client/${{ github.ref_name }})**' - - name: Submit metric to Datadog - uses: sendgrid/dx-automator/actions/datadog-release-metric@main - env: - DD_API_KEY: ${{ secrets.DATADOG_API_KEY }} + # PyPI trusted publishing (OIDC) - no API token. A trusted publisher must be + # configured on pypi.org for this repo and workflow. + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1 - notify-on-failure: - name: Slack notify on failure - if: failure() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref_type == 'tag') - needs: [ test, deploy ] - runs-on: ubuntu-latest - steps: - - uses: rtCamp/action-slack-notify@v2 - env: - SLACK_COLOR: failure - SLACK_ICON_EMOJI: ':github:' - SLACK_MESSAGE: ${{ format('Test *{0}*, Deploy *{1}*, {2}/{3}/actions/runs/{4}', needs.test.result, needs.deploy.result, github.server_url, github.repository, github.run_id) }} - SLACK_TITLE: Action Failure - ${{ github.repository }} - SLACK_USERNAME: GitHub Actions - SLACK_MSG_AUTHOR: twilio-dx - SLACK_FOOTER: Posted automatically using GitHub Actions - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} - MSG_MINIMAL: true +# - name: Submit metric to Datadog +# uses: sendgrid/dx-automator/actions/datadog-release-metric@08b601b726671445abc798ed59881766ec8fefc6 # main +# env: +# DD_API_KEY: ${{ secrets.DATADOG_API_KEY }} + +# notify-on-failure: +# name: Slack notify on failure +# if: failure() && github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || github.ref_type == 'tag') +# needs: [ test, deploy ] +# runs-on: ubuntu-x64 +# steps: +# - uses: rtCamp/action-slack-notify@e31e87e03dd19038e411e38ae27cbad084a90661 # v2.3.3 +# env: +# SLACK_COLOR: failure +# SLACK_ICON_EMOJI: ':github:' +# SLACK_MESSAGE: ${{ format('Test *{0}*, Deploy *{1}*, {2}/{3}/actions/runs/{4}', needs.test.result, needs.deploy.result, github.server_url, github.repository, github.run_id) }} +# SLACK_TITLE: Action Failure - ${{ github.repository }} +# SLACK_USERNAME: GitHub Actions +# SLACK_MSG_AUTHOR: twilio-dx +# SLACK_FOOTER: Posted automatically using GitHub Actions +# SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} +# MSG_MINIMAL: true