|
| 1 | +name: Build Python |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | + schedule: |
| 7 | + - cron: "0 0 1 * *" |
| 8 | + |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - main |
| 12 | + - develop |
| 13 | + paths: |
| 14 | + - 'python/**' |
| 15 | + - '.github/workflows/python.yml' |
| 16 | + |
| 17 | + release: |
| 18 | + types: [published] |
| 19 | + |
| 20 | +env: |
| 21 | + REGISTRY: ghcr.io |
| 22 | + |
| 23 | +jobs: |
| 24 | + build: |
| 25 | + name: "python:${{ matrix.version }}" |
| 26 | + runs-on: ubuntu-latest |
| 27 | + permissions: |
| 28 | + contents: read |
| 29 | + packages: write |
| 30 | + |
| 31 | + strategy: |
| 32 | + fail-fast: false |
| 33 | + matrix: |
| 34 | + version: |
| 35 | + - "3.7" |
| 36 | + - "3.8" |
| 37 | + - "3.9" |
| 38 | + |
| 39 | + steps: |
| 40 | + - name: Checkout code |
| 41 | + uses: actions/checkout@v4 |
| 42 | + |
| 43 | + - name: Set lowercase repository owner |
| 44 | + id: owner |
| 45 | + run: | |
| 46 | + echo "value=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT |
| 47 | +
|
| 48 | + - name: Check if Dockerfile exists |
| 49 | + id: check |
| 50 | + run: | |
| 51 | + if [ -f "./python/${{ matrix.version }}/Dockerfile" ]; then |
| 52 | + echo "exists=true" >> $GITHUB_OUTPUT |
| 53 | + else |
| 54 | + echo "exists=false" >> $GITHUB_OUTPUT |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Set up QEMU |
| 58 | + if: steps.check.outputs.exists == 'true' |
| 59 | + uses: docker/setup-qemu-action@v3 |
| 60 | + |
| 61 | + - name: Set up Docker Buildx |
| 62 | + if: steps.check.outputs.exists == 'true' |
| 63 | + uses: docker/setup-buildx-action@v3 |
| 64 | + |
| 65 | + - name: Login to GHCR |
| 66 | + if: steps.check.outputs.exists == 'true' |
| 67 | + uses: docker/login-action@v3 |
| 68 | + with: |
| 69 | + registry: ghcr.io |
| 70 | + username: ${{ github.repository_owner }} |
| 71 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 72 | + |
| 73 | + - name: Generate tags |
| 74 | + if: steps.check.outputs.exists == 'true' |
| 75 | + id: tags |
| 76 | + run: | |
| 77 | + OWNER="${{ steps.owner.outputs.value }}" |
| 78 | + VERSION="${{ matrix.version }}" |
| 79 | + TAGS="${{ env.REGISTRY }}/$OWNER/python:python_$VERSION" |
| 80 | + |
| 81 | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then |
| 82 | + TAGS="$TAGS,${{ env.REGISTRY }}/$OWNER/python:latest" |
| 83 | + elif [[ "${{ github.ref }}" == "refs/heads/develop" ]]; then |
| 84 | + TAGS="$TAGS,${{ env.REGISTRY }}/$OWNER/python:python_$VERSION-dev" |
| 85 | + elif [[ "${{ github.ref }}" == refs/tags/* ]]; then |
| 86 | + REL_TAG="${{ github.ref_name }}" |
| 87 | + TAGS="$TAGS,${{ env.REGISTRY }}/$OWNER/python:python_$VERSION-$REL_TAG" |
| 88 | + fi |
| 89 | + |
| 90 | + echo "tags=$TAGS" >> $GITHUB_OUTPUT |
| 91 | +
|
| 92 | + - name: Build and push |
| 93 | + if: steps.check.outputs.exists == 'true' |
| 94 | + uses: docker/build-push-action@v6 |
| 95 | + with: |
| 96 | + context: ./python |
| 97 | + file: ./python/${{ matrix.version }}/Dockerfile |
| 98 | + push: true |
| 99 | + platforms: linux/amd64,linux/arm64 |
| 100 | + tags: ${{ steps.tags.outputs.tags }} |
| 101 | + cache-from: type=gha |
| 102 | + cache-to: type=gha,mode=max |
0 commit comments