Skip to content

Commit bf0d4d6

Browse files
authored
Fix CI workflows for pull requests from forks (#526)
* Fix CI workflows for pull requests from forks * Remove dead plugins job from main workflow * Fix image fallback to key on secrets availability, not vars * Use public kurrentplatform/kurrentdb image for no-credential runs
1 parent 75f9bcf commit bf0d4d6

4 files changed

Lines changed: 59 additions & 65 deletions

File tree

.github/workflows/load-configuration.yml

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,37 @@ jobs:
5050
steps:
5151
- name: Set KurrentDB Runtime Configuration Properties
5252
id: set
53+
env:
54+
RUNTIME: ${{ inputs.runtime }}
55+
REGISTRY: ${{ inputs.registry }}
56+
IMAGE: ${{ inputs.image }}
57+
TAG: ${{ inputs.tag }}
58+
IMAGES: ${{ vars.KURRENTDB_DOCKER_IMAGES }}
59+
SECRETS_AVAILABLE: ${{ secrets.CLOUDSMITH_CICD_USER != '' }}
5360
run: |
54-
case ${{ inputs.runtime }} in
55-
"qa")
56-
echo "registry=${{ inputs.registry }}" >> $GITHUB_OUTPUT
57-
echo "image=${{ inputs.image }}" >> $GITHUB_OUTPUT
58-
echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT
59-
;;
61+
if [ "$RUNTIME" = "qa" ]; then
62+
{
63+
echo "registry=$REGISTRY"
64+
echo "image=$IMAGE"
65+
echo "tag=$TAG"
66+
} >> "$GITHUB_OUTPUT"
67+
exit 0
68+
fi
6069
61-
*)
62-
echo "registry=${{ fromJSON(vars.KURRENTDB_DOCKER_IMAGES)[inputs.runtime].registry }}" >> $GITHUB_OUTPUT
63-
echo "image=${{ fromJSON(vars.KURRENTDB_DOCKER_IMAGES)[inputs.runtime].image }}" >> $GITHUB_OUTPUT
64-
echo "tag=${{ fromJSON(vars.KURRENTDB_DOCKER_IMAGES)[inputs.runtime].tag }}" >> $GITHUB_OUTPUT
65-
;;
66-
esac
70+
# Runs without registry credentials must use the anonymously pullable
71+
# lts image: forks get neither vars nor secrets, dependabot gets vars
72+
# but not secrets, so key the fallback on secrets, not on vars.
73+
if [ "$SECRETS_AVAILABLE" != "true" ] || [ -z "$IMAGES" ]; then
74+
IMAGES='{"lts":{"registry":"docker.io/kurrentplatform","image":"kurrentdb","tag":"lts"}}'
75+
fi
76+
77+
CONFIG=$(jq -ce --arg runtime "$RUNTIME" '.[$runtime]' <<< "$IMAGES") || {
78+
echo "No image configuration for runtime '$RUNTIME'" >&2
79+
exit 1
80+
}
81+
82+
{
83+
echo "registry=$(jq -r '.registry' <<< "$CONFIG")"
84+
echo "image=$(jq -r '.image' <<< "$CONFIG")"
85+
echo "tag=$(jq -r '.tag' <<< "$CONFIG")"
86+
} >> "$GITHUB_OUTPUT"

.github/workflows/main.yml

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
- "**.md"
66
push:
77
branches:
8-
- main
8+
- master
99
schedule:
1010
- cron: "0 3 * * 0" # Every sunday at 3am UTC.
1111

@@ -45,7 +45,7 @@ jobs:
4545
name: Code quality
4646
runs-on: ubuntu-latest
4747
steps:
48-
- uses: actions/checkout@v3
48+
- uses: actions/checkout@v4
4949

5050
- name: Corepack
5151
run: corepack enable
@@ -64,65 +64,34 @@ jobs:
6464
git update-index --refresh
6565
git diff-index --exit-code --name-status HEAD --
6666
67+
select_runtimes:
68+
name: Select runtimes
69+
runs-on: ubuntu-latest
70+
outputs:
71+
runtimes: ${{ steps.set.outputs.runtimes }}
72+
env:
73+
# Secrets are not passed to runs from forks or dependabot. Without them,
74+
# only the anonymously pullable lts image can be tested.
75+
SECRETS_AVAILABLE: ${{ secrets.CLOUDSMITH_CICD_USER != '' }}
76+
steps:
77+
- id: set
78+
run: |
79+
if [ "$SECRETS_AVAILABLE" = "true" ]; then
80+
echo 'runtimes=["previous-lts", "lts", "ci"]' >> "$GITHUB_OUTPUT"
81+
else
82+
echo 'runtimes=["lts"]' >> "$GITHUB_OUTPUT"
83+
fi
84+
6785
tests:
68-
needs: validation
86+
needs: [validation, select_runtimes]
6987

7088
strategy:
7189
fail-fast: false
7290
matrix:
73-
runtime: [previous-lts, lts, ci]
91+
runtime: ${{ fromJSON(needs.select_runtimes.outputs.runtimes) }}
7492

7593
name: Tests
7694
uses: ./.github/workflows/tests.yml
7795
with:
7896
runtime: ${{ matrix.runtime }}
7997
secrets: inherit
80-
81-
plugins:
82-
needs: tests
83-
if: false
84-
name: "${{ matrix.group.name }}"
85-
strategy:
86-
fail-fast: false
87-
matrix:
88-
group:
89-
- name: plugins
90-
path: ./src/plugins
91-
env:
92-
# GitHub only passes secrets to the main repo, so we need to skip some things if they are unavailable
93-
SECRETS_AVAILABLE: ${{ secrets.EVENTSTORE_CLOUD_ID != null }}
94-
KURRENT_VERSION: "24.2.0-jammy"
95-
runs-on: ubuntu-latest
96-
steps:
97-
- uses: actions/checkout@v4
98-
99-
- uses: actions/setup-node@v4
100-
with:
101-
node-version-file: .github/files/.nvmrc
102-
103-
- name: NodeJS version
104-
run: node -v
105-
106-
- name: Corepack
107-
run: corepack enable
108-
109-
- name: Login to Cloudsmith
110-
uses: docker/login-action@v3
111-
with:
112-
registry: docker.eventstore.com
113-
username: ${{ secrets.CLOUDSMITH_CICD_USER }}
114-
password: ${{ secrets.CLOUDSMITH_CICD_TOKEN }}
115-
116-
- name: Install
117-
run: yarn
118-
119-
- name: Corepack
120-
run: corepack enable
121-
122-
- name: Build
123-
run: yarn build
124-
125-
- name: Run Tests
126-
run: yarn test ${{ matrix.group.path }} --ci --run-in-band --forceExit
127-
env:
128-
KURRENT_IMAGE: "docker.eventstore.com/eventstore-ee/eventstoredb-commercial:${{ env.KURRENT_VERSION }}"

.github/workflows/qa.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ jobs:
2626
registry: ${{ inputs.registry }}
2727
image: ${{ inputs.image }}
2828
tag: ${{ inputs.tag }}
29+
secrets: inherit

.github/workflows/tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
registry: ${{ inputs.registry }}
3131
image: ${{ inputs.image }}
3232
tag: ${{ inputs.tag }}
33+
secrets: inherit
3334

3435
test:
3536
needs: load_configuration
@@ -61,10 +62,13 @@ jobs:
6162
path: ./src/opentelemetry
6263

6364
runs-on: ubuntu-latest
65+
env:
66+
SECRETS_AVAILABLE: ${{ secrets.CLOUDSMITH_CICD_USER != '' }}
6467
steps:
6568
- uses: actions/checkout@v4
6669

6770
- name: Login to Cloudsmith
71+
if: env.SECRETS_AVAILABLE == 'true'
6872
uses: docker/login-action@v3
6973
with:
7074
registry: ${{ needs.load_configuration.outputs.registry }}

0 commit comments

Comments
 (0)