update-test-ubuntu-git.yml 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. name: Publish test-ubuntu-git Container
  2. on:
  3. # Use an on demand workflow trigger.
  4. # (Forked copies of actions/checkout won't have permission to update GHCR.io/actions,
  5. # so avoid trigger events that run automatically.)
  6. workflow_dispatch:
  7. inputs:
  8. publish:
  9. description: 'Publish to ghcr.io? (main branch only)'
  10. type: boolean
  11. required: true
  12. default: false
  13. env:
  14. REGISTRY: ghcr.io
  15. IMAGE_NAME: actions/test-ubuntu-git
  16. jobs:
  17. build-and-push-image:
  18. runs-on: ubuntu-latest
  19. # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
  20. permissions:
  21. contents: read
  22. packages: write
  23. steps:
  24. - name: Checkout repository
  25. uses: actions/checkout@v4
  26. # Use `docker/login-action` to log in to GHCR.io.
  27. # Once published, the packages are scoped to the account defined here.
  28. - name: Log in to the ghcr.io container registry
  29. uses: docker/login-action@v3.0.0
  30. with:
  31. registry: ${{ env.REGISTRY }}
  32. username: ${{ github.actor }}
  33. password: ${{ secrets.GITHUB_TOKEN }}
  34. - name: Format Timestamp
  35. id: timestamp
  36. # Use `date` with a custom format to achieve the key=value format GITHUB_OUTPUT expects.
  37. run: date -u "+now=%Y%m%d.%H%M%S.%3NZ" >> "$GITHUB_OUTPUT"
  38. - name: Issue Image Publish Warning
  39. if: ${{ inputs.publish && github.ref_name != 'main' }}
  40. run: echo "::warning::test-ubuntu-git images can only be published from the actions/checkout 'main' branch. Workflow will continue with push/publish disabled."
  41. # Use `docker/build-push-action` to build (and optionally publish) the image.
  42. - name: Build Docker Image (with optional Push)
  43. uses: docker/build-push-action@v5.1.0
  44. with:
  45. context: .
  46. file: images/test-ubuntu-git.Dockerfile
  47. # For now, attempts to push to ghcr.io must target the `main` branch.
  48. # In the future, consider also allowing attempts from `releases/*` branches.
  49. push: ${{ inputs.publish && github.ref_name == 'main' }}
  50. tags: |
  51. ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}.${{ steps.timestamp.outputs.now }}