|
1 | 1 | name: Publish Electric images to Docker Hub |
2 | 2 |
|
3 | 3 | # If you decide to modify the list of triggers for this action, don't forget to also update the |
4 | | -# conditional logic in the derive_build_vars and publish_tagged_image jobs. |
| 4 | +# conditional logic based on ${{ github.event_name }} in the derive_build_vars job. |
5 | 5 | on: |
6 | 6 | push: |
7 | 7 | branches: ['main'] |
8 | 8 | release: |
9 | 9 | types: [released] |
| 10 | + # Allows the workflow to be called by the Changesets workflow |
| 11 | + workflow_call: |
| 12 | + inputs: |
| 13 | + release_tag: |
| 14 | + description: 'The @core/sync-service@... tag passed from caller' |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + # Allows the workflow to be triggered manually from the UI |
10 | 18 | workflow_dispatch: |
11 | 19 | inputs: |
12 | 20 | release_tag: |
13 | | - description: 'The @core/sync-service@... tag to run for (e.g. @core/sync-service@v1.2.10)' |
| 21 | + description: 'The @core/sync-service@... tag to run the workflow for (e.g. @core/sync-service@1.2.10)' |
14 | 22 | required: true |
15 | 23 | type: string |
16 | 24 |
|
| 25 | +env: |
| 26 | + DOCKERHUB_REPO: electricsql/electric |
| 27 | + DOCKERHUB_CANARY_REPO: electricsql/electric-canary |
| 28 | + |
17 | 29 | jobs: |
18 | 30 | derive_build_vars: |
19 | 31 | name: Derive build variables from the source code |
20 | 32 | runs-on: blacksmith-2vcpu-ubuntu-2404 |
21 | 33 | outputs: |
| 34 | + git_ref: ${{ steps.git_ref.outputs.git_ref }} |
| 35 | + is_release: ${{ steps.git_ref.outputs.is_release }} |
22 | 36 | short_commit_sha: ${{ steps.vars.outputs.short_commit_sha }} |
23 | 37 | electric_version: ${{ steps.vars.outputs.electric_version }} |
24 | 38 |
|
25 | 39 | steps: |
| 40 | + - name: Determine the ref to check out |
| 41 | + id: git_ref |
| 42 | + run: | |
| 43 | + case ${{ github.event_name }} in |
| 44 | + push) |
| 45 | + ref="${{ github.sha }}" |
| 46 | + is_release=false |
| 47 | + ;; |
| 48 | +
|
| 49 | + release) |
| 50 | + ref="refs/tags/${{ github.event.release.tag_name }}" |
| 51 | + is_release=true |
| 52 | + ;; |
| 53 | +
|
| 54 | + workflow_dispatch | workflow_call) |
| 55 | + ref="refs/tags/${{ inputs.release_tag }}" |
| 56 | + is_release=true |
| 57 | + ;; |
| 58 | + esac |
| 59 | +
|
| 60 | + echo "git_ref=$ref" >> $GITHUB_OUTPUT |
| 61 | + echo "is_release=$is_release" >> $GITHUB_OUTPUT |
| 62 | +
|
26 | 63 | - uses: actions/checkout@v4 |
27 | 64 | with: |
28 | 65 | # The checked out commit influences the value of the ELECTRIC_VERSION variable |
|
35 | 72 | # |
36 | 73 | # For manual triggers via workflow_dispatch, we check out the tag specified manually |
37 | 74 | # by the actor. |
38 | | - ref: ${{ |
39 | | - github.event_name == 'release' && format('refs/tags/{0}', github.event.release.tag_name) || |
40 | | - github.event_name == 'workflow_dispatch' && format('refs/tags/{0}', inputs.release_tag) || |
41 | | - github.sha }} |
| 75 | + ref: ${{ steps.git_ref.outputs.git_ref }} |
42 | 76 | # Also important to fetch the whole history since otherwise we won't get that tags |
43 | 77 | # that are required to determine the correct ELECTRIC_VERSION. |
44 | 78 | fetch-depth: 0 |
|
69 | 103 | needs: [derive_build_vars] |
70 | 104 | steps: |
71 | 105 | - uses: actions/checkout@v4 |
| 106 | + with: |
| 107 | + ref: ${{ needs.derive_build_vars.outputs.git_ref }} |
72 | 108 |
|
73 | 109 | - uses: useblacksmith/setup-docker-builder@v1 |
74 | 110 |
|
|
93 | 129 | # the subsequent merge job will assemble the manifest list and apply tags |
94 | 130 | outputs: type=image,push-by-digest=true,name-canonical=true,push=true |
95 | 131 | tags: | |
96 | | - electricsql/electric |
97 | | - electricsql/electric-canary |
| 132 | + ${{ env.DOCKERHUB_REPO }} |
| 133 | + ${{ env.DOCKERHUB_CANARY_REPO }} |
98 | 134 |
|
99 | 135 | # Save the digest so the merge job can find both platform images |
100 | 136 | - name: Export digest |
@@ -126,39 +162,38 @@ jobs: |
126 | 162 |
|
127 | 163 | - name: Derive image tags from the GitHub Actions event |
128 | 164 | run: | |
129 | | - case ${{ github.event_name }} in |
130 | | - push) |
131 | | - # A regular push to the main branch triggers canary image publishing |
132 | | - echo "ELECTRIC_TAGS=-t electricsql/electric:canary" >> $GITHUB_ENV |
133 | | - echo "ELECTRIC_CANARY_TAGS=-t electricsql/electric-canary:latest -t electricsql/electric-canary:${{ needs.derive_build_vars.outputs.short_commit_sha }}" >> $GITHUB_ENV |
134 | | - ;; |
135 | | - release | workflow_dispatch) |
136 | | - # A release triggers official release image publishing |
137 | | - echo "ELECTRIC_TAGS=-t electricsql/electric:latest -t electricsql/electric:${{ needs.derive_build_vars.outputs.electric_version }}" >> $GITHUB_ENV |
138 | | - esac |
| 165 | + if [ "${{ needs.derive_build_vars.outputs.is_release }}" = "true" ]; then |
| 166 | + # A release triggers official release image publishing |
| 167 | + echo "ELECTRIC_TAGS=-t $DOCKERHUB_REPO:latest -t $DOCKERHUB_REPO:${{ needs.derive_build_vars.outputs.electric_version }}" >> $GITHUB_ENV |
| 168 | + echo "ELECTRIC_CANARY_TAGS=" >> $GITHUB_ENV |
| 169 | + else |
| 170 | + # A regular push to the main branch triggers canary image publishing |
| 171 | + echo "ELECTRIC_TAGS=-t $DOCKERHUB_REPO:canary" >> $GITHUB_ENV |
| 172 | + echo "ELECTRIC_CANARY_TAGS=-t $DOCKERHUB_CANARY_REPO:latest -t $DOCKERHUB_CANARY_REPO:${{ needs.derive_build_vars.outputs.short_commit_sha }}" >> $GITHUB_ENV |
| 173 | + fi |
139 | 174 |
|
140 | 175 | - name: Create multi-arch manifest list |
141 | 176 | run: | |
142 | 177 | set -euo pipefail |
143 | 178 |
|
144 | | - # Build a list of electricsql/electric@sha256:... source images |
| 179 | + # Build a list of $DOCKERHUB_REPO@sha256:... source images |
145 | 180 | ELECTRIC_IMAGES=$( |
146 | 181 | for f in /tmp/digests/*.digest; do |
147 | | - echo electricsql/electric@$(cat $f) |
| 182 | + echo $DOCKERHUB_REPO@$(cat $f) |
148 | 183 | done |
149 | 184 | ) |
150 | 185 |
|
151 | | - # Create a manifest list for electricsql/electric:canary that includes both platforms |
| 186 | + # Create a manifest list for $DOCKERHUB_REPO:canary that includes both platforms |
152 | 187 | docker buildx imagetools create $ELECTRIC_TAGS $ELECTRIC_IMAGES |
153 | 188 |
|
154 | 189 | if [ -n "$ELECTRIC_CANARY_TAGS" ]; then |
155 | | - # Build a list of electricsql/electric-canary@sha256:... source images |
| 190 | + # Build a list of $DOCKERHUB_CANARY_REPO@sha256:... source images |
156 | 191 | ELECTRIC_CANARY_IMAGES=$( |
157 | 192 | for f in /tmp/digests/*.digest; do |
158 | | - echo electricsql/electric-canary@$(cat $f) |
| 193 | + echo $DOCKERHUB_CANARY_REPO@$(cat $f) |
159 | 194 | done |
160 | 195 | ) |
161 | 196 |
|
162 | | - # Create a manifest list for electricsql/electric-canary:... that includes both platforms |
| 197 | + # Create a manifest list for $DOCKERHUB_CANARY_REPO:... that includes both platforms |
163 | 198 | docker buildx imagetools create $ELECTRIC_CANARY_TAGS $ELECTRIC_CANARY_IMAGES |
164 | 199 | fi |
0 commit comments