| 1 |
name: docker |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
branches: |
| 6 |
- "main" |
| 7 |
release: |
| 8 |
types: [published] |
| 9 |
|
| 10 |
permissions: |
| 11 |
contents: read |
| 12 |
|
| 13 |
env: |
| 14 |
REGISTRY: pyfound/black |
| 15 |
|
| 16 |
jobs: |
| 17 |
build: |
| 18 |
if: github.repository == 'psf/black' |
| 19 |
runs-on: ${{ matrix.runner }} |
| 20 |
name: build (${{ matrix.platform }}) |
| 21 |
strategy: |
| 22 |
matrix: |
| 23 |
include: |
| 24 |
- platform: linux/amd64 |
| 25 |
runner: ubuntu-latest |
| 26 |
- platform: linux/arm64 |
| 27 |
runner: ubuntu-24.04-arm |
| 28 |
steps: |
| 29 |
- name: Checkout |
| 30 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 31 |
with: |
| 32 |
persist-credentials: false |
| 33 |
|
| 34 |
- name: Set up Docker Buildx |
| 35 |
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 |
| 36 |
|
| 37 |
- name: Login to DockerHub |
| 38 |
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 |
| 39 |
with: |
| 40 |
username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 41 |
password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 42 |
|
| 43 |
- name: Prepare |
| 44 |
id: prepare |
| 45 |
run: echo "platform=${platform//\//-}" >> $GITHUB_OUTPUT |
| 46 |
env: |
| 47 |
platform: ${{ matrix.platform }} |
| 48 |
|
| 49 |
- name: Build and push |
| 50 |
id: build |
| 51 |
uses: docker/build-push-action@bcafcacb16a39f128d818304e6c9c0c18556b85f # v7.1.0 |
| 52 |
with: |
| 53 |
context: . |
| 54 |
platforms: ${{ matrix.platform }} |
| 55 |
outputs: type=image,push-by-digest=true,name-canonical=true,push=true |
| 56 |
tags: ${{ env.REGISTRY }} |
| 57 |
cache-from: type=gha,scope=${{ steps.prepare.outputs.platform }} |
| 58 |
cache-to: type=gha,scope=${{ steps.prepare.outputs.platform }},mode=max |
| 59 |
|
| 60 |
- name: Export digest |
| 61 |
run: | |
| 62 |
mkdir -p digests |
| 63 |
touch "digests/${digest#sha256:}" |
| 64 |
env: |
| 65 |
digest: ${{ steps.build.outputs.digest }} |
| 66 |
|
| 67 |
- name: Upload digest |
| 68 |
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 69 |
with: |
| 70 |
name: digests-${{ steps.prepare.outputs.platform }} |
| 71 |
path: digests/* |
| 72 |
if-no-files-found: error |
| 73 |
|
| 74 |
push: |
| 75 |
runs-on: ubuntu-latest |
| 76 |
needs: build |
| 77 |
|
| 78 |
steps: |
| 79 |
- name: Checkout |
| 80 |
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 81 |
with: |
| 82 |
persist-credentials: false |
| 83 |
|
| 84 |
- name: Download digests |
| 85 |
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 86 |
with: |
| 87 |
path: digests |
| 88 |
pattern: digests-* |
| 89 |
merge-multiple: true |
| 90 |
|
| 91 |
- name: Login to DockerHub |
| 92 |
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0 |
| 93 |
with: |
| 94 |
username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 95 |
password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 96 |
|
| 97 |
- name: Set up Docker Buildx |
| 98 |
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0 |
| 99 |
|
| 100 |
- name: Create manifest list and push |
| 101 |
run: | |
| 102 |
TAGS="-t $REGISTRY:latest" |
| 103 |
|
| 104 |
if [[ "$EVENT_NAME" == "release" ]]; then |
| 105 |
TAGS="$TAGS -t $REGISTRY:$(git describe --candidates=0 --tags)" |
| 106 |
|
| 107 |
if [[ "$PRERELEASE" == "true" ]]; then |
| 108 |
TAGS="$TAGS -t $REGISTRY:latest_prerelease" |
| 109 |
else |
| 110 |
TAGS="$TAGS -t $REGISTRY:latest_release" |
| 111 |
fi |
| 112 |
else |
| 113 |
TAGS="$TAGS -t $REGISTRY:latest_non_release" |
| 114 |
fi |
| 115 |
|
| 116 |
cd digests |
| 117 |
docker buildx imagetools create $TAGS $(printf "$REGISTRY@sha256:%s " *) |
| 118 |
env: |
| 119 |
EVENT_NAME: ${{ github.event_name }} |
| 120 |
PRERELEASE: ${{ github.event.release.prerelease }} |
| 121 |
|
| 122 |
- name: Inspect image |
| 123 |
run: docker buildx imagetools inspect $REGISTRY:latest |