Skip to content

Commit 67d289a

Browse files
authored
Updates the hash-secrets logic (#73)
Signed-off-by: Roshan Khatri <rvkhatri@amazon.com>
1 parent 6d00dde commit 67d289a

File tree

2 files changed

+27
-17
lines changed

2 files changed

+27
-17
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,22 @@ on:
66
branches:
77
- mainline
88
paths:
9-
- '**/Dockerfile'
9+
- "**/Dockerfile"
1010
workflow_dispatch:
1111

1212
env:
1313
IS_PULL: ${{ github.event_name == 'pull_request' }}
14-
HAS_SECRETS: ${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' && secrets.DOCKERHUB_ACCOUNT != '' && secrets.DOCKERHUB_REPOSITORY != '' }}
1514

1615
defaults:
1716
run:
18-
shell: 'bash -Eeuo pipefail -x {0}'
17+
shell: "bash -Eeuo pipefail -x {0}"
1918

2019
jobs:
21-
2220
generate-jobs:
2321
name: Generate Jobs
2422
runs-on: ubuntu-latest
2523
outputs:
2624
strategy: ${{ steps.generate-jobs.outputs.strategy }}
27-
has-secrets: ${{ steps.generate-jobs.outputs.has-secrets }}
2825
steps:
2926
- uses: actions/checkout@v4
3027
with:
@@ -49,11 +46,12 @@ jobs:
4946
fi
5047
5148
echo "strategy=$(jq -c . <<<"$strategy")" >> "$GITHUB_OUTPUT"
52-
echo "has-secrets=${{ env.HAS_SECRETS }}" >> "$GITHUB_OUTPUT"
5349
jq . <<<"$strategy" # debugging aid to visually inspect the generated matrix
5450
# Job to build and push Docker images individually for each architecture/platform
5551
build_and_push:
5652
needs: [generate-jobs]
53+
env:
54+
HAS_SECRETS: ${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' && secrets.DOCKERHUB_ACCOUNT != '' && secrets.DOCKERHUB_REPOSITORY != '' }}
5755
strategy:
5856
fail-fast: false # continue other jobs even if one job fails
5957
matrix:
@@ -133,7 +131,7 @@ jobs:
133131
cache-from: type=gha
134132
cache-to: type=gha,mode=max
135133
pull: true
136-
134+
137135
- name: Prepare Environment
138136
run: ${{ matrix.version.runs.prepare }}
139137

@@ -149,37 +147,37 @@ jobs:
149147
- name: Set up Python
150148
uses: actions/setup-python@v4
151149
with:
152-
python-version: '3.8'
150+
python-version: "3.8"
153151

154-
# Core + Module Integration Tests
152+
# Core + Module Integration Tests
155153
- name: All Core + Module Tests
156154
run: |
157155
matrix_version="${{ matrix.version.name }}"
158156
bundle_version=$(echo "$matrix_version" | cut -d'.' -f1-2)
159-
157+
160158
./.test/tests/valkey-integration-tests/run.sh "${{ env.DOCKER_REPO_NAME }}" "$bundle_version"
161-
159+
162160
# Export digest to a file to reference it later in merging manifests
163161
- name: Export digest
164162
id: export-digest
165163
run: |
166164
mkdir -p ${{ runner.temp }}/digests
167165
digest="${{ steps.build.outputs.digest }}"
168166
touch "${{ runner.temp }}/digests/${digest#sha256:}"
169-
167+
170168
version="${{ matrix.version.name }}"
171169
major_minor=$(echo "$version" | cut -d'.' -f1-2)
172-
170+
173171
directory="${{ matrix.version.meta.entries[0].directory }}"
174172
if [[ "$directory" == *"alpine"* ]]; then
175173
distro="alpine"
176174
else
177175
distro="debian"
178176
fi
179-
177+
180178
echo "linux_distro=$distro" >> "$GITHUB_OUTPUT"
181179
echo "version_major_minor=$major_minor" >> "$GITHUB_OUTPUT"
182-
180+
183181
- name: Upload digest for version-distro combination
184182
uses: actions/upload-artifact@v4
185183
with:
@@ -192,6 +190,10 @@ jobs:
192190
merge-manifest:
193191
runs-on: ubuntu-latest
194192
needs: [generate-jobs, build_and_push]
193+
env:
194+
HAS_SECRETS: ${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' && secrets.DOCKERHUB_ACCOUNT != '' && secrets.DOCKERHUB_REPOSITORY != '' }}
195+
outputs:
196+
has-secrets: ${{ steps.output-has-secrets.outputs.has-secrets }}
195197
steps:
196198
- name: Set DOCKER_REPO_NAME dynamically
197199
run: |
@@ -201,6 +203,10 @@ jobs:
201203
echo "DOCKER_REPO_NAME=${{ secrets.DOCKERHUB_ACCOUNT }}/valkey-bundle" >> $GITHUB_ENV
202204
fi
203205
206+
- name: Output if User has set secrets
207+
id: output-has-secrets
208+
run: echo "has-secrets=${{ env.HAS_SECRETS }}" >> "$GITHUB_OUTPUT"
209+
204210
- name: Download All Digests
205211
uses: actions/download-artifact@v4
206212
with:
@@ -286,11 +292,11 @@ jobs:
286292
done
287293
288294
update-dockerhub-description:
289-
if: github.event_name == 'push' && github.ref == 'refs/heads/mainline' && needs.generate-jobs.outputs.has-secrets == 'true'
295+
if: github.event_name == 'push' && github.ref == 'refs/heads/mainline' && needs.merge-manifest.outputs.has-secrets == 'true'
290296
needs: [merge-manifest, generate-jobs]
291297
name: Update DockerHub Description
292298
uses: ./.github/workflows/update-dockerhub-docs.yml
293299
secrets:
294300
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
295301
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
296-
DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }}
302+
DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }}

.github/workflows/update-dockerhub-docs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ on:
1111
DOCKERHUB_REPOSITORY:
1212
required: true
1313

14+
env:
15+
HAS_SECRETS: ${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' && secrets.DOCKERHUB_REPOSITORY != '' }}
16+
1417
jobs:
1518
update-dockerhub:
1619
name: Update Dockerhub description
@@ -20,6 +23,7 @@ jobs:
2023
steps:
2124
- uses: actions/checkout@v4
2225
- name: Docker Hub Description
26+
if: ${{ env.HAS_SECRETS }}
2327
uses: peter-evans/dockerhub-description@v4
2428
with:
2529
username: ${{ secrets.DOCKERHUB_USERNAME }}

0 commit comments

Comments
 (0)