Replace Docker image and versions with variables (#22) #22
  
    
      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
    
  
  
    
  | --- | |
| name: Test, Build, and Push Docker Image | |
| on: # yamllint disable-line rule:truthy | |
| push: | |
| branches: ["main"] | |
| tags: | |
| - "v*" | |
| pull_request: | |
| branches: ["main"] | |
| release: | |
| types: ["created"] | |
| # GOAL: | |
| # on pushes to main branch or v* tag | |
| # - ruff, mdlint, yamllint, test | |
| # on PRs against main branch | |
| # - ruff, mdlint, yamllint, test | |
| # on Release creation | |
| # - ruff, mdlint, yamllint, test | |
| # on the above events when the triggered actor is the repo owner | |
| # - docker | |
| # on Release creation (ex: maybe a maintainer that isn't repo owner) | |
| # - docker | |
| jobs: | |
| ruff: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| - name: Run Ruff linter | |
| uses: astral-sh/ruff-action@v1 | |
| with: | |
| args: "check" | |
| changed-files: "true" | |
| - name: Run Ruff formatter | |
| uses: astral-sh/ruff-action@v1 | |
| with: | |
| args: "format --check --diff" | |
| changed-files: "true" | |
| mdlint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| - name: Run markdownlint-cli2 | |
| uses: DavidAnson/markdownlint-cli2-action@v17 | |
| # file globbing configured in .markdownlint-cli2.yaml | |
| yamllint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| - name: Run yamllint | |
| uses: ibiqlik/action-yamllint@v3 | |
| with: | |
| file_or_dir: . | |
| test: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - "ruff" | |
| - "mdlint" | |
| - "yamllint" | |
| strategy: | |
| matrix: | |
| python-version: ["3.9", "3.10", "3.11", "3.12"] | |
| env: | |
| test_dir: tests | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Run Python unit tests | |
| run: python -m unittest discover -v -s ${{ env.test_dir }} | |
| docker: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| packages: write | |
| needs: | |
| - "test" | |
| if: >- | |
| ${{ | |
| github.triggering_actor == github.repository_owner || | |
| github.event_name == 'release' && github.event.action == 'created' | |
| }} | |
| steps: | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: | | |
| ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=ref,event=tag | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| # git short commit | |
| type=sha | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| push: true | |
| platforms: linux/amd64,linux/arm64 | |
| tags: ${{ steps.meta.outputs.tags }} | |
| ... |