From 8930dc10bcfd384b9f6ee206c2d2311ed794d6c0 Mon Sep 17 00:00:00 2001 From: Paul Schifferer Date: Mon, 4 Mar 2024 07:49:21 -0800 Subject: [PATCH] GitHub workflows --- .github/dependabot.yml | 18 +++++ .github/workflows/debug.yml | 74 ++++++++++++++++++ .github/workflows/docker-build.yml | 91 ++++++++++++++++++++++ .github/workflows/python-ci.yml | 98 ++++++++++++++++++++++++ .github/workflows/python-pr.yml | 52 +++++++++++++ .github/workflows/python-update-reqs.yml | 37 +++++++++ 6 files changed, 370 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/debug.yml create mode 100644 .github/workflows/docker-build.yml create mode 100644 .github/workflows/python-ci.yml create mode 100644 .github/workflows/python-pr.yml create mode 100644 .github/workflows/python-update-reqs.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..9666bae --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,18 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "pip" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + open-pull-requests-limit: 5 + assignees: + - "paulyhedral" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/debug.yml b/.github/workflows/debug.yml new file mode 100644 index 0000000..b7f1ebf --- /dev/null +++ b/.github/workflows/debug.yml @@ -0,0 +1,74 @@ +name: Debug + +on: + create: + tags: + - '*' + release: + types: + - published + - created + push: + branches: + - '*' + +jobs: + debug: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: Dump job context + env: + JOB_CONTEXT: ${{ toJson(job) }} + run: echo "$JOB_CONTEXT" + - name: Dump steps context + env: + STEPS_CONTEXT: ${{ toJson(steps) }} + run: echo "$STEPS_CONTEXT" + - name: Dump runner context + env: + RUNNER_CONTEXT: ${{ toJson(runner) }} + run: echo "$RUNNER_CONTEXT" + - name: Dump strategy context + env: + STRATEGY_CONTEXT: ${{ toJson(strategy) }} + run: echo "$STRATEGY_CONTEXT" + - name: Dump matrix context + env: + MATRIX_CONTEXT: ${{ toJson(matrix) }} + run: echo "$MATRIX_CONTEXT" + - name: Get current date + id: getbuilddate + run: | + echo "::set-output name=date::$(date -u)" + echo "::set-output name=isodate::$(date -u '+%Y-%m-%dT%H:%M:%S')" + echo "::set-output name=tagdate::$(date -u '+%Y%m%d%H%M%S')" + echo "::set-output name=timestamp::$(date -u '+%s')" + - name: 'Get Previous tag' + id: previoustag + uses: actions-ecosystem/action-get-latest-tag@v1 + with: + semver_only: true + initial_version: v0.0.0 + with_initial_version: true + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + registry.sweetrpg.com/sweetrpg-main-web + tags: | + type=raw,value=latest + type=raw,value=${{ steps.previoustag.outputs.tag }} + type=raw,value=${{ steps.getbuilddate.outputs.date }} + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml new file mode 100644 index 0000000..b4fbc6f --- /dev/null +++ b/.github/workflows/docker-build.yml @@ -0,0 +1,91 @@ +name: Docker Build + +concurrency: docker + +on: + push: + branches: + - develop + paths: + - Dockerfile + - scripts/entrypoint.sh + workflow_run: + workflows: ["CI"] + branches: [develop] + types: + - completed + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: "Get Previous tag" + id: previoustag + uses: actions-ecosystem/action-get-latest-tag@v1 + with: + semver_only: true + initial_version: v0.0.0 + with_initial_version: true + - name: Get current date + id: getbuilddate + run: | + echo "::set-output name=date::$(date -u)" + echo "::set-output name=isodate::$(date -u '+%Y-%m-%dT%H:%M:%S')" + echo "::set-output name=tagdate::$(date -u '+%Y%m%d%H%M%S')" + echo "::set-output name=timestamp::$(date -u '+%s')" + - name: Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ghcr.io/sweetrpg/catalog-api + tags: | + type=raw,value=latest + type=raw,value=${{ steps.previoustag.outputs.tag }} + type=raw,value=${{ steps.getbuilddate.outputs.tagdate }} + type=ref,event=branch + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + id: docker_build + uses: docker/build-push-action@v3 + with: + # context: . + push: true + no-cache: true + tags: ${{ steps.meta.outputs.tags }} + build-args: | + BUILD_NUMBER=${{ github.run_number }} + BUILD_JOB=${{ github.job }} + BUILD_SHA=${{ github.sha }} + BUILD_DATE=${{ steps.getbuilddate.outputs.isodate }} + BUILD_VERSION=${{ steps.previoustag.outputs.tag }} + # tags: registry.sweetrpg.com/sweetrpg-catalog-api:latest + # - name: Scan image + # uses: sysdiglabs/scan-action@v1 + # with: + # image-tag: registry.sweetrpg.com/sweetrpg-catalog-api:latest + # sysdig-secure-token: ${{ secrets.SYSDIG_SECURE_TOKEN }} + - name: Create Sentry release + uses: getsentry/action-release@v1 + env: + SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + SENTRY_ORG: ${{ vars.SENTRY_ORG }} + SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }} + with: + environment: ${{ vars.SENTRY_ENV }} diff --git a/.github/workflows/python-ci.yml b/.github/workflows/python-ci.yml new file mode 100644 index 0000000..fc31036 --- /dev/null +++ b/.github/workflows/python-ci.yml @@ -0,0 +1,98 @@ +name: CI + +concurrency: ci-${{ github.ref }} + +on: + push: + branches: [develop] + paths: + - "src/**" + - "tests/**" + - setup.cfg + - setup.py + - tox.ini + - "requirements/**" + - "docs/**" + workflow_run: + workflows: ["Update Requirements"] + types: [completed] + +jobs: + tests: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + concurrency: ci + strategy: + fail-fast: false + matrix: + include: + - { + name: Linux, + python: "3.10", + os: ubuntu-latest, + tox: py310, + } + # - { + # name: Windows, + # python: "3.10", + # os: windows-latest, + # tox: py310, + # } + # - { name: Mac, python: "3.10", os: macos-latest, tox: py310 } + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + - name: update-pip + run: | + pip install -U wheel + pip install -U setuptools + python -m pip install -U pip + - name: get-pip-cache-dir + id: pip-cache + run: echo "::set-output name=dir::$(pip cache dir)" + - name: cache-pip + uses: actions/cache@v3 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: pip|${{ runner.os }}|${{ matrix.python }}|${{ hashFiles('setup.py') }}|${{ hashFiles('requirements/*.txt') }} + - name: install-utils + run: pip install tox + - name: tests + run: tox -e ${{ matrix.tox }} + + # docs: + # needs: [tests] + # runs-on: ubuntu-latest + # concurrency: docs + # steps: + # - uses: actions/checkout@v3 + # - uses: actions/setup-python@v4 + # with: + # python-version: "3.10" + # - name: install-deps + # run: pip install -r requirements/docs.txt + # - name: make-docs + # run: cd docs && make html + # - name: publish-docs + # uses: peaceiris/actions-gh-pages@v3 + # with: + # github_token: ${{ secrets.GITHUB_TOKEN }} + # publish_dir: ./docs/_build/html + + tag: + needs: [tests] + runs-on: ubuntu-latest + concurrency: publish + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: publish + uses: relekang/python-semantic-release@master + with: + additional_options: "--patch" + github_token: ${{ secrets.GITHUB_TOKEN }} + repository_username: __token__ + repository_password: ${{ secrets.PYPI_TOKEN }} diff --git a/.github/workflows/python-pr.yml b/.github/workflows/python-pr.yml new file mode 100644 index 0000000..e39bd75 --- /dev/null +++ b/.github/workflows/python-pr.yml @@ -0,0 +1,52 @@ +name: PR + +concurrency: pr-${{ github.ref }} + +on: + pull_request: + branches: [develop] + paths: + - "src/**" + - "tests/**" + - setup.cfg + - setup.py + - tox.ini + - "requirements/**" + - "docs/**" + +jobs: + tests: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - { + name: Linux, + python: "3.10", + os: ubuntu-latest, + tox: py310, + } + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + - name: update-pip + run: | + pip install -U wheel + pip install -U setuptools + python -m pip install -U pip + - name: get-pip-cache-dir + id: pip-cache + run: echo "::set-output name=dir::$(pip cache dir)" + - name: cache-pip + uses: actions/cache@v3 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: pip|${{ runner.os }}|${{ matrix.python }}|${{ hashFiles('setup.py') }}|${{ hashFiles('requirements/*.txt') }} + - name: install-utils + run: pip install tox + - name: tests + run: tox -e ${{ matrix.tox }} diff --git a/.github/workflows/python-update-reqs.yml b/.github/workflows/python-update-reqs.yml new file mode 100644 index 0000000..8adacba --- /dev/null +++ b/.github/workflows/python-update-reqs.yml @@ -0,0 +1,37 @@ +name: Update Requirements + +on: + workflow_dispatch: + repository_dispatch: + types: + - model-core-published + - api-core-published + - catalog-objects-published + - db-published + schedule: + - cron: "0 1 * * 1" + push: + branches: + - develop + paths: + - "requirements/*.in" + - setup.py + +jobs: + update-reqs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.10" + - name: update-reqs + run: | + pip install -U wheel setuptools pip-tools + git config --global user.email "ci@sweetrpg.com" + git config --global user.name "SweetRPG Requirement Updater" + git checkout ${{ github.head_ref || github.ref_name }} + scripts/update-requirements.sh + git add requirements/*.txt + git commit -m "Update requirements" + git push origin