|
1 | | -# |
2 | 1 | name: Docker Image CI |
3 | 2 |
|
4 | | -# Configures this workflow to run every time a change is pushed to the |
5 | | -# branch called `main`. |
| 3 | +# Two ways in: |
| 4 | +# - push of a calver tag (YY.MM or YY.MM.p) → publishes <version>, latest, main |
| 5 | +# - workflow_dispatch → publishes latest + main from whichever ref the user |
| 6 | +# picks in the Actions UI. Used to fast-forward :latest/:main when the |
| 7 | +# branch has moved ahead of the most recent release tag. |
6 | 8 | on: |
7 | | - push: |
8 | | - tags: |
9 | | - - '*.*.*' |
10 | | - branches: |
11 | | - - 'main' |
| 9 | + push: |
| 10 | + tags: |
| 11 | + - '[0-9][0-9].[0-9][0-9]' |
| 12 | + - '[0-9][0-9].[0-9][0-9].[0-9]*' |
| 13 | + workflow_dispatch: |
| 14 | + inputs: |
| 15 | + push_latest: |
| 16 | + description: 'Push :latest tag' |
| 17 | + type: boolean |
| 18 | + default: true |
| 19 | + push_main: |
| 20 | + description: 'Push :main tag' |
| 21 | + type: boolean |
| 22 | + default: true |
12 | 23 |
|
13 | | -# Defines two custom environment variables for the workflow. These are used |
14 | | -# for the Container registry domain, and a name for the Docker image that |
15 | | -# this workflow builds. |
16 | 24 | env: |
17 | | - REGISTRY: ghcr.io |
18 | | - IMAGE_NAME: ${{ github.repository }} |
| 25 | + REGISTRY: ghcr.io |
| 26 | + IMAGE_NAME: ${{ github.repository }} |
19 | 27 |
|
20 | | -# There is a single job in this workflow. It's configured to run on the |
21 | | -# latest available version of Ubuntu. |
22 | 28 | jobs: |
23 | | - build-and-push-image: |
24 | | - runs-on: ubuntu-latest |
| 29 | + build-and-push-image: |
| 30 | + runs-on: ubuntu-latest |
25 | 31 |
|
26 | | - # Sets the permissions granted to the `GITHUB_TOKEN` for the actions |
27 | | - # in this job. |
28 | | - permissions: |
29 | | - contents: read |
30 | | - packages: write |
| 32 | + permissions: |
| 33 | + contents: read |
| 34 | + packages: write |
31 | 35 |
|
32 | | - steps: |
33 | | - - name: Checkout repository |
34 | | - uses: actions/checkout@v4 |
| 36 | + steps: |
| 37 | + - name: Validate calver tag |
| 38 | + if: github.event_name == 'push' |
| 39 | + env: |
| 40 | + REF_NAME: ${{ github.ref_name }} |
| 41 | + run: | |
| 42 | + if ! [[ "$REF_NAME" =~ ^[0-9]{2}\.[0-9]{2}(\.[0-9]+)?$ ]]; then |
| 43 | + echo "Tag '$REF_NAME' does not match YY.MM or YY.MM.p calver format." |
| 44 | + exit 1 |
| 45 | + fi |
35 | 46 |
|
36 | | - # Uses the `docker/login-action` action to log in to the Container |
37 | | - # registry using the account and password that will publish the packages. |
38 | | - # Once published, the packages are scoped to the account defined here. |
39 | | - - name: Log in to GitHub Package Container registry |
40 | | - uses: docker/login-action@v3 |
41 | | - with: |
42 | | - registry: ${{ env.REGISTRY }} |
43 | | - username: ${{ github.actor }} |
44 | | - password: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + - name: Checkout repository |
| 48 | + uses: actions/checkout@v4 |
45 | 49 |
|
46 | | - - name: Set up QEMU |
47 | | - uses: docker/setup-qemu-action@v3 |
| 50 | + - name: Log in to GitHub Package Container registry |
| 51 | + uses: docker/login-action@v3 |
| 52 | + with: |
| 53 | + registry: ${{ env.REGISTRY }} |
| 54 | + username: ${{ github.actor }} |
| 55 | + password: ${{ secrets.GITHUB_TOKEN }} |
48 | 56 |
|
49 | | - - name: Set up Docker Buildx |
50 | | - uses: docker/setup-buildx-action@v3 |
| 57 | + - name: Log in to Docker Hub |
| 58 | + uses: docker/login-action@v3 |
| 59 | + with: |
| 60 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 61 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
51 | 62 |
|
52 | | - # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) |
53 | | - # to extract tags and labels that will be applied to the specified image. |
54 | | - # The `id` "meta" allows the output of this step to be referenced in |
55 | | - # a subsequent step. The `images` value provides the base name for the |
56 | | - # tags and labels. |
57 | | - - name: Extract metadata (tags, labels) for Docker |
58 | | - id: meta |
59 | | - uses: docker/metadata-action@v5 |
60 | | - with: |
61 | | - images: "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}" |
62 | | - tags: | |
63 | | - type=semver,pattern={{version}} |
64 | | - type=ref,event=branch |
| 63 | + - name: Set up QEMU |
| 64 | + uses: docker/setup-qemu-action@v3 |
65 | 65 |
|
66 | | - # This step uses the `docker/build-push-action` action to build the |
67 | | - # image, based on your repository's `Dockerfile`. If the build succeeds, |
68 | | - # it pushes the image to GitHub Packages. |
69 | | - # It uses the `context` parameter to define the build's context as the |
70 | | - # set of files located in the specified path. For more information, see |
71 | | - # "[Usage](https://github.com/docker/build-push-action#usage)" in the |
72 | | - # README of the `docker/build-push-action` repository. |
73 | | - # It uses the `tags` and `labels` parameters to tag and label the image |
74 | | - # with the output from the "meta" step. |
75 | | - - name: Build and push Docker image |
76 | | - uses: docker/build-push-action@v5 |
77 | | - with: |
78 | | - platforms: linux/amd64,linux/arm64 |
79 | | - context: . |
80 | | - push: ${{ github.event_name != 'pull_request' }} |
81 | | - tags: ${{ steps.meta.outputs.tags }} |
82 | | - labels: ${{ steps.meta.outputs.labels }} |
83 | | - cache-from: type=gha |
84 | | - cache-to: type=gha,mode=max |
| 66 | + - name: Set up Docker Buildx |
| 67 | + uses: docker/setup-buildx-action@v3 |
| 68 | + |
| 69 | + - name: Extract metadata (tags, labels) for Docker |
| 70 | + id: meta |
| 71 | + uses: docker/metadata-action@v5 |
| 72 | + with: |
| 73 | + images: | |
| 74 | + ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 75 | + heyputer/puter |
| 76 | + # type=ref,event=tag only emits on tag pushes, so manual runs skip |
| 77 | + # the calver tag and just publish whichever of latest / main the |
| 78 | + # dispatch inputs asked for. On a tag push, both default to true. |
| 79 | + tags: | |
| 80 | + type=ref,event=tag |
| 81 | + type=raw,value=latest,enable=${{ github.event_name == 'push' || inputs.push_latest }} |
| 82 | + type=raw,value=main,enable=${{ github.event_name == 'push' || inputs.push_main }} |
| 83 | +
|
| 84 | + - name: Build and push Docker image |
| 85 | + uses: docker/build-push-action@v5 |
| 86 | + with: |
| 87 | + platforms: linux/amd64,linux/arm64 |
| 88 | + context: . |
| 89 | + push: true |
| 90 | + tags: ${{ steps.meta.outputs.tags }} |
| 91 | + labels: ${{ steps.meta.outputs.labels }} |
| 92 | + cache-from: type=gha |
| 93 | + cache-to: type=gha,mode=max |
| 94 | + |
| 95 | + - name: Sync README to Docker Hub |
| 96 | + uses: peter-evans/dockerhub-description@v4 |
| 97 | + with: |
| 98 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 99 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 100 | + repository: heyputer/puter |
| 101 | + readme-filepath: ./README.md |
0 commit comments