Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ jobs:
export DEFAULT_SERVICE="https://www.googleapis.com/compute/v1/projects/ghost-activitypub/global/backendServices/stg-netherlands-activitypub-api"
export PR_SERVICE="https://www.googleapis.com/compute/v1/projects/ghost-activitypub/global/backendServices/stg-pr-${{ github.event.pull_request.number }}-api"
# Add host rules and path matchers if they don't exist
yq -i '.hostRules = (.hostRules // [{"hosts": ["activitypub.ghostinfra.net"], "pathMatcher": "staging-environments"}])' config.yml
yq -i '.pathMatchers = (.pathMatchers // [{"name": "staging-environments", "defaultService": "'"$DEFAULT_SERVICE"'", "routeRules": []}])' config.yml
yq -i '.hostRules = (.hostRules // [{"hosts": ["activitypub.ghostinfra.net"], "pathMatcher": "all-paths"}])' config.yml
yq -i '.pathMatchers = (.pathMatchers // [{"name": "all-paths", "defaultService": "'"$DEFAULT_SERVICE"'", "routeRules": []}])' config.yml
# Remove existing route rules for the PR service
Comment on lines +280 to 282
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Potential logic issue merging URL map defaults with // operator.
The expressions use (.hostRules // [...]) and (.pathMatchers // [...]), which only set defaults when these fields are missing or null, leaving existing arrays untouched instead of appending or updating entries. This may prevent the all-paths matcher from being applied for ephemeral staging if the fields already exist.
Consider using appends (+=) or transforming existing entries (e.g., map) to update or add the new matcher.

🤖 Prompt for AI Agents
In .github/workflows/cicd.yml around lines 280 to 282, the current use of the
`//` operator only sets default values if `.hostRules` or `.pathMatchers` are
missing or null, but does not append or update existing arrays. To fix this,
modify the yq commands to append the new host rule and path matcher to the
existing arrays using the `+=` operator or use a map transformation to update or
add the `all-paths` matcher, ensuring the ephemeral staging configuration is
correctly applied even when these fields already exist.

yq -i '.pathMatchers[] |= (.routeRules |= map(select((.routeAction.weightedBackendServices // []) | length == 0 or .routeAction.weightedBackendServices[0].backendService != env(PR_SERVICE))))' config.yml
# Add new route rules for the PR service
export MAX_PRIORITY=$(yq '[.pathMatchers[] | select(.name == "staging-environments") | .routeRules[]?.priority] | max // 0' config.yml)
export MAX_PRIORITY=$(yq '[.pathMatchers[] | select(.name == "all-paths") | .routeRules[]?.priority] | max // 0' config.yml)
export NEXT_PRIORITY=$((MAX_PRIORITY + 1))
LABELS_JSON=$(echo "$LABELS" | jq -c '[.[] | select(.name | test("\\.ghost\\.is$")) | .name]')
for LABEL in $(echo "$LABELS_JSON" | jq -r '.[]'); do
Expand Down Expand Up @@ -368,6 +368,16 @@ jobs:
labels: |-
commit-sha=${{ github.sha }}

- name: "Deploy ActivityPub External to Cloud Run"
uses: google-github-actions/deploy-cloudrun@v2
with:
image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.build-test-push.outputs.activitypub_docker_version }}
region: ${{ matrix.region }}
service: stg-${{ matrix.region_name }}-activitypub-external
skip_default_labels: true
labels: |-
commit-sha=${{ github.sha }}

- name: "Deploy ActivityPub API to Cloud Run"
uses: google-github-actions/deploy-cloudrun@v2
with:
Expand Down Expand Up @@ -422,6 +432,16 @@ jobs:
labels: |-
commit-sha=${{ github.sha }}

- name: "Deploy ActivityPub External to Cloud Run"
uses: google-github-actions/deploy-cloudrun@v2
with:
image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.build-test-push.outputs.activitypub_docker_version }}
region: ${{ matrix.region }}
service: prd-${{ matrix.region_name }}-activitypub-external
skip_default_labels: true
labels: |-
commit-sha=${{ github.sha }}

- name: "Deploy ActivityPub API to Cloud Run"
uses: google-github-actions/deploy-cloudrun@v2
with:
Expand Down