|
1 | 1 | name: Publish Docker image |
| 2 | + |
| 3 | +# Triggers on release tags for the CLI package. Version comes directly |
| 4 | +# from the tag ref (create-awesome-python-app@X.Y.Z). |
2 | 5 | on: |
3 | 6 | push: |
4 | 7 | tags: |
5 | 8 | - "create-awesome-python-app@*" |
| 9 | + # Manual trigger to rebuild an image for an existing version. |
6 | 10 | workflow_dispatch: |
7 | 11 | inputs: |
8 | 12 | version: |
9 | | - description: "Package version" |
| 13 | + description: "Package version (e.g. 0.1.0)" |
10 | 14 | required: true |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + |
11 | 19 | jobs: |
12 | 20 | docker: |
| 21 | + name: Build and push Docker image |
13 | 22 | runs-on: ubuntu-latest |
14 | 23 | steps: |
15 | | - - uses: actions/checkout@v4 |
16 | | - - name: Login to Docker Hub |
17 | | - uses: docker/login-action@v3 |
| 24 | + - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 |
| 25 | + with: |
| 26 | + persist-credentials: false |
| 27 | + |
| 28 | + - name: Resolve version |
| 29 | + id: version |
| 30 | + env: |
| 31 | + TAG_REF: ${{ github.ref_name }} |
| 32 | + INPUT_VERSION: ${{ github.event.inputs.version }} |
| 33 | + run: | |
| 34 | + if [ -n "$INPUT_VERSION" ]; then |
| 35 | + VERSION="$INPUT_VERSION" |
| 36 | + else |
| 37 | + # Tag format: create-awesome-python-app@X.Y.Z |
| 38 | + VERSION="${TAG_REF#create-awesome-python-app@}" |
| 39 | + fi |
| 40 | + MAJOR=$(echo "$VERSION" | cut -d. -f1) |
| 41 | + MINOR=$(echo "$VERSION" | cut -d. -f2) |
| 42 | + { |
| 43 | + echo "version=$VERSION" |
| 44 | + echo "major=$MAJOR" |
| 45 | + echo "minor=$MINOR" |
| 46 | + } >> "$GITHUB_OUTPUT" |
| 47 | +
|
| 48 | + - name: Set up QEMU |
| 49 | + # Required so buildx can cross-build linux/arm64 on the x86_64 |
| 50 | + # ubuntu-latest runner. |
| 51 | + uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0 |
| 52 | + with: |
| 53 | + platforms: linux/arm64 |
| 54 | + |
| 55 | + - name: Set up Docker Buildx |
| 56 | + uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0 |
| 57 | + |
| 58 | + - name: Log in to Docker Hub |
| 59 | + uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0 |
18 | 60 | with: |
19 | 61 | username: ${{ secrets.DOCKERHUB_USERNAME }} |
20 | 62 | password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 63 | + |
| 64 | + - name: Extract Docker metadata |
| 65 | + id: meta |
| 66 | + uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0 |
| 67 | + with: |
| 68 | + images: ulisesjeremias/create-awesome-python-app |
| 69 | + # `latest` is pushed on tag pushes AND on explicit workflow_dispatch |
| 70 | + # runs (which always execute against main, so they represent the |
| 71 | + # current release). |
| 72 | + tags: | |
| 73 | + type=raw,value=latest |
| 74 | + type=raw,value=${{ steps.version.outputs.version }} |
| 75 | + type=raw,value=${{ steps.version.outputs.major }}.${{ steps.version.outputs.minor }} |
| 76 | + type=raw,value=v${{ steps.version.outputs.major }} |
| 77 | + labels: | |
| 78 | + org.opencontainers.image.title=create-awesome-python-app |
| 79 | + org.opencontainers.image.description=Composable scaffolding CLI for production-ready Python apps |
| 80 | + org.opencontainers.image.url=https://github.com/Create-Python-App/create-python-app |
| 81 | + org.opencontainers.image.source=https://github.com/Create-Python-App/create-python-app |
| 82 | + org.opencontainers.image.licenses=MIT |
| 83 | + org.opencontainers.image.version=${{ steps.version.outputs.version }} |
| 84 | +
|
21 | 85 | - name: Build and push |
22 | | - uses: docker/build-push-action@v6 |
| 86 | + uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 |
23 | 87 | with: |
24 | 88 | context: . |
25 | 89 | push: true |
26 | | - tags: | |
27 | | - ${{ secrets.DOCKERHUB_USERNAME }}/create-awesome-python-app:latest |
| 90 | + platforms: linux/amd64,linux/arm64 |
| 91 | + tags: ${{ steps.meta.outputs.tags }} |
| 92 | + labels: ${{ steps.meta.outputs.labels }} |
| 93 | + build-args: | |
| 94 | + VERSION=${{ steps.version.outputs.version }} |
| 95 | + cache-from: type=gha |
| 96 | + cache-to: type=gha,mode=max |
0 commit comments