update-test-ubuntu-git.yml 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. # Use `docker/build-push-action` to build (and optionally publish) the image.
  39. - name: Build and push Docker image
  40. uses: docker/build-push-action@v5.1.0
  41. with:
  42. context: .
  43. file: images/test-ubuntu-git.Dockerfile
  44. # For now, attempts to push to ghcr.io must target the `main` branch.
  45. # In the future, consider also allowing attempts from `releases/*` branches.
  46. push: ${{ inputs.publish && github.ref_name == 'main' }}
  47. tags: |
  48. ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}.${{ steps.timestamp.outputs.now }}