Skip to content

Commit d0fc255

Browse files
authored
fix: remove secrets from if conditions in publish workflow (#51)
- GitHub Actions doesn't allow secrets in job-level if conditions - Move secret checks to runtime steps instead - Add explicit credential checking steps for NPM, Docker, and Slack - This ensures the workflow runs without syntax errors
1 parent f39d3f5 commit d0fc255

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

.github/workflows/publish.yml

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,19 @@ jobs:
5959
- name: Build
6060
run: pnpm build
6161

62+
- name: Check NPM token
63+
id: check-npm
64+
run: |
65+
if [ -n "${{ secrets.NPM_TOKEN }}" ]; then
66+
echo "has_token=true" >> $GITHUB_OUTPUT
67+
echo "✅ NPM_TOKEN is configured"
68+
else
69+
echo "has_token=false" >> $GITHUB_OUTPUT
70+
echo "⚠️ NPM_TOKEN is not configured, skipping publish"
71+
fi
72+
6273
- name: Publish to NPM
63-
if: ${{ secrets.NPM_TOKEN != '' }}
74+
if: steps.check-npm.outputs.has_token == 'true'
6475
run: |
6576
# Remove private flag if present
6677
jq 'del(.private)' package.json > tmp.json && mv tmp.json package.json
@@ -118,7 +129,7 @@ jobs:
118129
docker:
119130
name: Publish to Docker Hub
120131
runs-on: ubuntu-latest
121-
if: vars.ENABLE_DOCKER_RELEASE == 'true' && secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != ''
132+
if: vars.ENABLE_DOCKER_RELEASE == 'true'
122133
steps:
123134
- name: Determine version
124135
id: version
@@ -133,20 +144,36 @@ jobs:
133144
with:
134145
ref: v${{ steps.version.outputs.version }}
135146

147+
- name: Check Docker credentials
148+
id: check-docker
149+
run: |
150+
if [ -n "${{ secrets.DOCKERHUB_USERNAME }}" ] && [ -n "${{ secrets.DOCKERHUB_TOKEN }}" ]; then
151+
echo "has_credentials=true" >> $GITHUB_OUTPUT
152+
echo "✅ Docker Hub credentials are configured"
153+
else
154+
echo "has_credentials=false" >> $GITHUB_OUTPUT
155+
echo "⚠️ Docker Hub credentials are not configured, skipping publish"
156+
exit 0
157+
fi
158+
136159
- name: Set up QEMU
160+
if: steps.check-docker.outputs.has_credentials == 'true'
137161
uses: docker/setup-qemu-action@v3
138162

139163
- name: Set up Docker Buildx
164+
if: steps.check-docker.outputs.has_credentials == 'true'
140165
uses: docker/setup-buildx-action@v3
141166

142167
- name: Login to Docker Hub
168+
if: steps.check-docker.outputs.has_credentials == 'true'
143169
uses: docker/login-action@v3
144170
with:
145171
username: ${{ secrets.DOCKERHUB_USERNAME }}
146172
password: ${{ secrets.DOCKERHUB_TOKEN }}
147173

148174
- name: Extract metadata
149175
id: meta
176+
if: steps.check-docker.outputs.has_credentials == 'true'
150177
uses: docker/metadata-action@v5
151178
with:
152179
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ github.event.repository.name }}
@@ -157,6 +184,7 @@ jobs:
157184
type=raw,value=latest
158185
159186
- name: Build and push
187+
if: steps.check-docker.outputs.has_credentials == 'true'
160188
uses: docker/build-push-action@v6
161189
with:
162190
context: .
@@ -170,11 +198,21 @@ jobs:
170198

171199
notify:
172200
name: Notify
173-
if: always() && secrets.SLACK_WEBHOOK != ''
201+
if: always()
174202
needs: [npm, docker, github-packages]
175203
runs-on: ubuntu-latest
176204
steps:
205+
- name: Check Slack webhook
206+
id: check-slack
207+
run: |
208+
if [ -n "${{ secrets.SLACK_WEBHOOK }}" ]; then
209+
echo "has_webhook=true" >> $GITHUB_OUTPUT
210+
else
211+
echo "has_webhook=false" >> $GITHUB_OUTPUT
212+
fi
213+
177214
- name: Send Slack notification
215+
if: steps.check-slack.outputs.has_webhook == 'true'
178216
uses: slackapi/slack-github-action@v2
179217
with:
180218
payload: |

0 commit comments

Comments
 (0)