add docker-build/push to CI #267
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # run test suites | |
| name: Tests and Deployment | |
| on: | |
| - pull_request | |
| - push | |
| - release | |
| - workflow_dispatch | |
| # cancel the current workflow if another commit was pushed on the same PR or reference | |
| # uses the GitHub workflow name to avoid collision with other workflows running on the same PR/reference | |
| concurrency: | |
| group: "${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}" | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| jobs: | |
| # see: https://github.com/fkirc/skip-duplicate-actions | |
| skip_duplicate: | |
| name: Skip Duplicate Workflows | |
| continue-on-error: true | |
| runs-on: ubuntu-latest | |
| outputs: | |
| should_skip: ${{ steps.skip_duplicate.outputs.should_skip && ! contains(github.ref, 'refs/tags') && ! contains(github.ref, 'refs/heads/master') }} | |
| steps: | |
| - id: skip_check | |
| uses: fkirc/skip-duplicate-actions@master | |
| with: | |
| concurrent_skipping: "same_content" | |
| skip_after_successful_duplicate: "true" | |
| do_not_skip: '["pull_request", "workflow_dispatch", "schedule", "release"]' | |
| # see: https://github.com/actions/setup-python | |
| tests: | |
| name: Test | |
| needs: skip_duplicate | |
| if: ${{ needs.skip_duplicate.outputs.should_skip != 'true' }} | |
| runs-on: ${{ matrix.os }} | |
| continue-on-error: ${{ matrix.allow-failure }} | |
| env: | |
| # override make command to install directly in active python | |
| CONDA_CMD: "" | |
| services: | |
| # Label used to access the service container | |
| mongodb: | |
| image: mongo:3.4.23 # DockerHub | |
| ports: | |
| - "27017:27017" | |
| strategy: | |
| matrix: | |
| os: [ubuntu-latest] | |
| python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | |
| allow-failure: [false] | |
| test-case: [test-local] | |
| include: | |
| # linter tests | |
| - os: ubuntu-latest | |
| python-version: 3.11 | |
| allow-failure: false | |
| test-case: lint | |
| # coverage test | |
| - os: ubuntu-latest | |
| python-version: 3.11 | |
| allow-failure: false | |
| test-case: coverage | |
| # smoke test of Docker image | |
| - os: ubuntu-latest | |
| python-version: None # doesn't matter which one (in docker), but match default of repo | |
| allow-failure: false | |
| test-case: docker-test | |
| # deprecated versions | |
| - os: ubuntu-latest | |
| python-version: 3.8 # EOL 2024-10 | |
| allow-failure: false | |
| test-case: test-local | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | |
| with: | |
| fetch-depth: "0" | |
| persist-credentials: false | |
| - name: Set up Python3 | |
| if: ${{ matrix.python-version != 'None' }} | |
| uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: 'pip' | |
| - name: Install Dependencies | |
| if: ${{ matrix.python-version != 'None' }} | |
| # install package and dependencies directly, | |
| # skip sys/conda setup to use active python | |
| run: make install develop | |
| - name: Display Packages | |
| if: ${{ matrix.python-version != 'None' }} | |
| run: pip freeze | |
| - name: Display Environment Variables | |
| run: | | |
| hash -r | |
| env | sort | |
| - name: Run Tests | |
| run: make --no-keep-going ${{ matrix.test-case }} | |
| - name: Stop Workers | |
| if: ${{ matrix.python-version == 'None' }} | |
| run: make docker-stop | |
| - name: Upload coverage report | |
| uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2 | |
| if: ${{ success() && matrix.test-case == 'coverage' }} | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: ./coverage/coverage.xml | |
| fail_ci_if_error: true | |
| verbose: true | |
| # FIXME: We should split the deployment job into its own workflow. Token-based updates to PyPI are heavily discouraged in favour of Trusted Publishing. | |
| deploy_pypi: | |
| name: Deploy (PyPI) | |
| needs: tests | |
| # Don't match master branch for upload to avoid duplicate error, even if the tag is usually applied on master. | |
| if: ${{ success() && github.event_name == 'push' && contains(github.ref, 'refs/tags') }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | |
| with: | |
| fetch-depth: "0" | |
| persist-credentials: false | |
| - name: Set up Python3 | |
| uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0 | |
| with: | |
| python-version: "3.11" | |
| - name: Build Distribution Package | |
| run: | | |
| make develop dist | |
| - name: Push Package to PyPi | |
| uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0 | |
| with: | |
| user: __token__ | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| verbose: true # For debugging 'twine upload' if a problem occurs. | |
| deploy_docker: | |
| name: Deploy (DockerHub) | |
| needs: tests | |
| if: ${{ success() && (contains(github.ref, 'refs/tags') || github.ref == 'refs/heads/master') }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 | |
| with: | |
| fetch-depth: "0" | |
| persist-credentials: false | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3.10.0 | |
| # FIXME: We should be using a PAT generated specifically for this. docker/build-push-action accepts PATs directly. | |
| - name: Login to DockerHub | |
| uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build Docker image | |
| uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0 | |
| with: | |
| file: "Dockerfile" | |
| push: true | |
| tags: birdhouse/twitcher:latest,birdhouse/twitcher:${{ github.ref_name }} |