|
1 | | -name: Publishes the test-ubuntu-git Container Image |
| 1 | +name: Publish test-ubuntu-git Container |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | # Use an on demand workflow trigger. |
|
7 | 7 | workflow_dispatch: |
8 | 8 | inputs: |
9 | 9 | publish: |
10 | | - description: 'Publish to ghcr.io?' |
| 10 | + description: 'Publish to ghcr.io? (main branch only)' |
11 | 11 | type: boolean |
12 | 12 | required: true |
13 | 13 | default: false |
@@ -37,20 +37,19 @@ jobs: |
37 | 37 | username: ${{ github.actor }} |
38 | 38 | password: ${{ secrets.GITHUB_TOKEN }} |
39 | 39 |
|
40 | | - # Use `docker/metadata-action` to preserve tags and labels that exist on the GHCR.io container image. |
41 | | - # - name: Extract metadata (tags, labels) for Docker |
42 | | - # id: meta |
43 | | - |
44 | | - # with: |
45 | | - # images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 40 | + - name: Format Timestamp |
| 41 | + id: timestamp |
| 42 | + # Use `date` with a custom format to achieve the key=value format GITHUB_OUTPUT expects. |
| 43 | + run: date -u "+now=%Y%m%d.%H%M%S.%3NZ" >> "$GITHUB_OUTPUT" |
46 | 44 |
|
47 | 45 | # Use `docker/build-push-action` to build (and optionally publish) the image. |
48 | 46 | - name: Build and push Docker image |
49 | 47 | |
50 | 48 | with: |
51 | 49 | context: . |
52 | 50 | file: images/test-ubuntu-git.Dockerfile |
53 | | - push: ${{ inputs.publish }} |
54 | | - tags: ${{ env.IMAGE_NAME }}:sha-${{ env.GITHUB_SHA }} |
55 | | - # tags: ${{ steps.meta.outputs.tags }} |
56 | | - # labels: ${{ steps.meta.outputs.labels }} |
| 51 | + # For now, attempts to push to ghcr.io must target the `main` branch. |
| 52 | + # In the future, consider also allowing attempts from `releases/*` branches. |
| 53 | + push: ${{ inputs.publish && github.ref_name == 'main' }} |
| 54 | + tags: | |
| 55 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}.${{ steps.timestamp.outputs.now }} |
0 commit comments