Skip to content

Added ephemeral staging environments#432

Merged
rmgpinto merged 2 commits intomainfrom
ephemeral-staging-envs
Apr 16, 2025
Merged

Added ephemeral staging environments#432
rmgpinto merged 2 commits intomainfrom
ephemeral-staging-envs

Conversation

@rmgpinto
Copy link
Copy Markdown
Collaborator

closes https://linear.app/ghost/issue/AP-976

  • Added ephemeral staging environments

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 24, 2025

Walkthrough

This pull request updates the GitHub Actions workflow configuration file by renaming the workflow from "CI" to "CICD" and refining the pull_request trigger to respond only to specific actions: opened, synchronize, reopened, labeled, and unlabeled. Permissions are extended to include read access for pull-requests. The build-test-push job's environment is renamed from "staging" to "build", and steps involving GCP authentication, Artifact Registry login, and Docker image pushing are conditionally executed only for pull_request events with the specified actions. A new deploy-pr job is added to deploy ephemeral staging environments when a pull request label matches the pattern "*.ghost.is". This job performs label checking, checks out two repositories, sets up Terraform with a version read from a file, modifies Terraform module URLs and backend prefixes, authenticates with GCP, runs Terraform init and apply, deploys migrations to Cloud Run, and updates a GCP load balancer URL map to route traffic to the ephemeral environment. The deploy-staging and deploy-production jobs remain but have their environment declarations removed.

Possibly related PRs

  • Added production cicd #473: Both PRs modify GitHub Actions workflows to enhance CICD processes, specifically adding or refining deployment jobs for staging and production environments, indicating a direct relation in managing deployment pipelines.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb6739c and e33a7ae.

📒 Files selected for processing (1)
  • .github/workflows/cicd.yml (5 hunks)
🔇 Additional comments (5)
.github/workflows/cicd.yml (5)

51-51: Confirm environment name change is intentional.

The environment for build-test-push is now set to build (was previously staging). Ensure this aligns with your deployment and access control requirements, as environment names can affect secrets and environment protection rules.


108-139: Conditional GCP and Docker steps: robust and correct.

The conditional execution of GCP authentication, Artifact Registry login, and Docker image push steps for specific pull request actions is correct and prevents unnecessary operations. This improves security and efficiency.


148-274: Ephemeral staging deploy: robust, modular, and secure.

The deploy-pr job is well-structured:

  • Label check logic is robust (-n "$LABEL_NAMES").
  • All steps are gated on the label match output.
  • Uses actions/checkout@v4 for both infra and terraform repos (addresses previous security advisories).
  • Terraform version is dynamically read and used.
  • GCP authentication uses a dedicated service account for staging environments.
  • Load balancer update script uses set -euo pipefail and cleans up temp files, addressing past review feedback.
  • Route rule YAML structure is correct.
  • Secrets are referenced securely.

No critical issues found. The job is modular, maintainable, and follows best practices.


243-273: Shell script: error handling and cleanup are robust.

The load balancer update script includes set -euo pipefail and uses mv to atomically update config files. Temporary files are cleaned up, and the script is clear and maintainable. All past review feedback on error handling and YAML correctness is addressed.


275-389: No issues with deploy-staging and deploy-production jobs.

These jobs remain unchanged except for the removal of environment declarations. The steps are standard for GCP Cloud Run deployments and use secure authentication and secret handling.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🔭 Outside diff range comments (1)
.github/workflows/deploy.yml (1)

97-103: ⚠️ Potential issue

Critical Issue: Undefined Output in Deploy-Old for ActivityPub API

Finally, the "Deploy ActivityPub API to Cloud Run" step in the deploy-old job references the same undefined output. To ensure proper image deployment, update this reference to correctly obtain the intended version information from the CI workflow.

🧰 Tools
🪛 actionlint (1.7.4)

100-100: property "build-test-push" is not defined in object type {}

(expression)

🧹 Nitpick comments (1)
.github/workflows/deploy.yml (1)

10-33: Deploy Ephemeral Staging: Variable Usage & Environment Naming

The ephemeral staging job properly handles Google Cloud authentication and checks if the infrastructure is already provisioned. Two points to consider:

  1. Variable Availability: The command uses GITHUB_HEAD_REF to filter services. Since workflow_run contexts may not always populate this variable (which is more typical in pull request events), please verify its availability or consider an alternative identifier.
  2. Environment Naming: The job is configured with environment: build. In the context of ephemeral staging, a more descriptive name (e.g., ephemeral-staging) might improve clarity in your deployment logs and reports.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 037b8fc and 07388f2.

📒 Files selected for processing (2)
  • .github/workflows/build.yml (1 hunks)
  • .github/workflows/deploy.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/deploy.yml

52-52: property "build-test-push" is not defined in object type {}

(expression)


60-60: property "build-test-push" is not defined in object type {}

(expression)


67-67: property "build-test-push" is not defined in object type {}

(expression)


85-85: property "build-test-push" is not defined in object type {}

(expression)


93-93: property "build-test-push" is not defined in object type {}

(expression)


100-100: property "build-test-push" is not defined in object type {}

(expression)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build, Test and Push
🔇 Additional comments (2)
.github/workflows/build.yml (1)

6-11: Enhanced Pull Request Event Triggers

The addition of specific pull request event types (opened, synchronize, reopened, labeled, and unlabeled) improves the granularity of workflow triggers for PR events. This should help ensure that changes are properly tested during development.

.github/workflows/deploy.yml (1)

1-8: Solid Setup for the New Deployment Workflow

The workflow is clearly set up to trigger on workflow_run for the "CI" workflow with the completed type. This ensures that the deployment process only begins after the CI process finishes. It would be beneficial to document in your repository how the outputs from the CI workflow (like the image version tags) are expected to be passed along, as they are referenced later in the file.

Comment thread .github/workflows/deploy.yml Outdated
Comment thread .github/workflows/deploy.yml Outdated
Comment thread .github/workflows/deploy.yml Outdated
Comment thread .github/workflows/deploy.yml Outdated
Comment thread .github/workflows/deploy.yml Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
.github/workflows/deploy.yml (1)

85-117: ⚠️ Potential issue

Deploy-Old Job: Missing Dependency Declaration
Similarly, the "deploy-old" job uses outputs from the ci-docker-tags job without declaring a dependency on it. This can result in undefined outputs during execution. To ensure that the necessary data is available, add the dependency like so:

-    runs-on: ubuntu-latest
+    needs: [ci-docker-tags]
+    runs-on: ubuntu-latest
🧰 Tools
🪛 actionlint (1.7.4)

99-99: property "ci-docker-tags" is not defined in object type {}

(expression)


107-107: property "ci-docker-tags" is not defined in object type {}

(expression)


114-114: property "ci-docker-tags" is not defined in object type {}

(expression)

🧹 Nitpick comments (1)
.github/workflows/deploy.yml (1)

9-23: CI Docker Tags Job: Output Extraction
The ci-docker-tags job correctly downloads the docker_tags artifact and extracts the Docker tag values for activitypub and migrations. Consider adding error handling or a check to ensure that docker_tags.txt exists and contains the expected content; this would help avoid unexpected failures in subsequent deployment jobs if the artifact is missing or malformed.

🛑 Comments failed to post (1)
.github/workflows/deploy.yml (1)

48-84: ⚠️ Potential issue

Deploy-Staging Job: Missing Dependency Declaration
This job references outputs from the ci-docker-tags job using expressions such as ${{ needs.ci-docker-tags.outputs.migrations_docker_tags }} and ${{ needs.ci-docker-tags.outputs.activitypub_docker_tags }}. However, there is no dependency declared using the needs: keyword, which means these outputs may not be available and could lead to runtime errors. To fix this, add the dependency to ensure that the ci-docker-tags job completes before this job starts. For example:

-    name: (staging) Deploy
+    needs: [ci-docker-tags]
+    name: (staging) Deploy
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

  deploy-staging:
    if: github.ref == 'refs/heads/main'
    needs: [ci-docker-tags]
    name: (staging) Deploy
    environment: build
    runs-on: ubuntu-latest
    strategy:
      matrix:
        region: [europe-west4, europe-west3]
    steps:
      - name: "Auth with Google Cloud"
        uses: 'google-github-actions/auth@v2'
        with:
          credentials_json: ${{ secrets.SERVICE_ACCOUNT_KEY }}

      - name: "Deploy Migrations to Cloud Run"
        if: ${{ matrix.region == 'europe-west4' }}
        uses: 'google-github-actions/deploy-cloudrun@v2'
        with:
          image: europe-docker.pkg.dev/ghost-activitypub/activitypub/migrations:${{ needs.ci-docker-tags.outputs.migrations_docker_tags }}
          region: ${{ matrix.region }}
          job: stg-${{ matrix.region }}-activitypub-migrations
          flags: '--wait --execute-now --set-cloudsql-instances=ghost-activitypub:${{ matrix.region }}:stg-${{ matrix.region }}-activitypub-primary'

      - name: "Deploy ActivityPub Queue to Cloud Run"
        uses: 'google-github-actions/deploy-cloudrun@v2'
        with:
          image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.ci-docker-tags.outputs.activitypub_docker_tags }}
          region: ${{ matrix.region }}
          service: stg-${{ matrix.region }}-activitypub-queue

      - name: "Deploy ActivityPub API to Cloud Run"
        uses: 'google-github-actions/deploy-cloudrun@v2'
        with:
          image: europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:${{ needs.ci-docker-tags.outputs.activitypub_docker_tags }}
          region: ${{ matrix.region }}
          service: stg-${{ matrix.region }}-activitypub-api
🧰 Tools
🪛 actionlint (1.7.4)

66-66: property "ci-docker-tags" is not defined in object type {}

(expression)


74-74: property "ci-docker-tags" is not defined in object type {}

(expression)


81-81: property "ci-docker-tags" is not defined in object type {}

(expression)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
.github/workflows/deploy.yml (1)

85-117: ⚠️ Potential issue

Deploy-Old Job – Ensure Consistent Image Tag References
Similarly, the deploy-old job references outputs from the ci-docker-tags job (e.g., ${{ needs.ci-docker-tags.outputs.migrations_docker_tags }}). This setup is dependent on the proper declaration of job outputs in the ci-docker-tags job. Once the outputs are defined at the job level, these references should resolve correctly.

🧰 Tools
🪛 actionlint (1.7.4)

99-99: property "ci-docker-tags" is not defined in object type {}

(expression)


107-107: property "ci-docker-tags" is not defined in object type {}

(expression)


114-114: property "ci-docker-tags" is not defined in object type {}

(expression)

🧹 Nitpick comments (1)
.github/workflows/build.yml (1)

99-101: Commented Out Test Step – Verify Intentional Disablement
The "Run Tests" step has been commented out. If this is an intentional decision (perhaps because tests are handled elsewhere or temporarily disabled during staging deployments), please add an inline comment explaining the rationale to avoid confusion in the future.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d6970c0 and 623a891.

📒 Files selected for processing (2)
  • .github/workflows/build.yml (3 hunks)
  • .github/workflows/deploy.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/deploy.yml

66-66: property "ci-docker-tags" is not defined in object type {}

(expression)


74-74: property "ci-docker-tags" is not defined in object type {}

(expression)


81-81: property "ci-docker-tags" is not defined in object type {}

(expression)


99-99: property "ci-docker-tags" is not defined in object type {}

(expression)


107-107: property "ci-docker-tags" is not defined in object type {}

(expression)


114-114: property "ci-docker-tags" is not defined in object type {}

(expression)

🔇 Additional comments (3)
.github/workflows/build.yml (2)

6-11: Enhanced Pull Request Trigger Events
The addition of the extra pull_request event types (opened, synchronize, reopened, labeled, unlabeled) broadens the scope of events triggering this workflow. This ensures that changes affecting PR metadata are caught early.


130-139: Output and Upload Docker Tags Steps Added
The new steps to output Docker tags to a file and subsequently upload them as an artifact correctly support the new CD workflow. Ensure that the file path and artifact name remain consistent with what the deployment workflow expects.

.github/workflows/deploy.yml (1)

1-8: Continuous Deployment Workflow Trigger Configuration
The CD workflow is now configured to trigger on the completion of the CI workflow via workflow_run. This setup is well suited to ensure that deployment steps run only after CI completes successfully.

Comment thread .github/workflows/deploy.yml Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
.github/workflows/build.yml (2)

149-155: Update Checkout Action Version for activitypub-infra Repo
This step is using actions/checkout@v3, which is flagged as outdated. Upgrading to actions/checkout@v4 is recommended for improved reliability.

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.4)

151-151: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


157-163: Update Checkout Action Version for Terraform Repo
Similarly, the terraform repo checkout uses actions/checkout@v3. Please update this to actions/checkout@v4.

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.4)

159-159: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🧹 Nitpick comments (2)
.github/workflows/build.yml (2)

134-147: Quote Shell Variable for Robustness
In the label-checking step, the condition uses

if [ $LABEL_NAMES != "" ]; then

For safer shell scripting (avoiding issues if LABEL_NAMES is empty or contains spaces), please quote the variable as follows:

if [ "$LABEL_NAMES" != "" ]; then

177-183: Review Module URL Replacement Command
The sed commands update module URLs correctly. However, the replacement pattern:

sed -i 's/REPLACE_ME/${{ github.event.pull_request.number }}/g' terraform.tf

may not substitute the PR number as expected due to the usage of single quotes. Confirm that GitHub Actions processes the expression as intended or consider switching to double quotes to guarantee interpolation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 869f80d and d553386.

📒 Files selected for processing (1)
  • .github/workflows/build.yml (2 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/build.yml

151-151: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


159-159: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


199-199: property "build-test-push" is not defined in object type {}

(expression)

🔇 Additional comments (8)
.github/workflows/build.yml (8)

3-6: PR Trigger Events Configuration
The pull request trigger now explicitly includes types [opened, synchronize, reopened, labeled], which is appropriate for ephemeral staging environments.


127-132: Deploy-pr Job Configuration
The new deploy-pr job is properly conditioned on pull request events and configured for the staging environment. The job’s overall structure aligns well with the ephemeral staging purpose.


165-169: Verify Terraform Version File Presence
The command correctly reads the Terraform version from
activitypub-infra/infrastructure/activitypub-staging-environments/.terraform-version
Ensure that this file exists in the repository as expected.


171-176: Terraform Setup Configuration is Correct
The terraform setup step properly uses the output from the previous step. No modifications are needed here.


185-190: Google Cloud Authentication Step is Correct
The authentication step with Google Cloud is configured properly using the provided service account key.


191-195: Terraform Init Step Configuration
The Terraform initialization command in this step is clear and effective.


208-212: Load Balancer Update Step Looks Good
The commands to export and display the current URL maps are straightforward and appear functional.


40-48:

Details

❓ Verification inconclusive

Note on Commented-out build-test-push Job
The build-test-push job block is currently commented out. However, its outputs are referenced later in the Terraform apply step. This discrepancy can lead to undefined output errors during deployment.

Please consider re-enabling this job or updating the dependent steps to source these outputs from a valid alternative.


Below is a shell script to search for references to the commented-out job outputs and the job itself. This will help verify if outputs from the build-test-push job (i.e. migrations_docker_version and activitypub_docker_version) are indeed used later—especially in parts of the Terraform workflow. Once these commands run, we can better decide if re-enabling this job or updating downstream steps is required.


🏁 Script executed:

#!/bin/bash
echo "Searching for references of 'migrations_docker_version' in the repository:"
rg "migrations_docker_version" -n .

echo "Searching for references of 'activitypub_docker_version' in the repository:"
rg "activitypub_docker_version" -n .

echo "Searching for references to the commented-out job 'build-test-push':"
rg "build-test-push" -n .

echo "Searching for references to 'terraform apply' (to check dependent steps):"
rg "terraform apply" -n .

Length of output: 774


Action Required: Verify Downstream Dependencies for Commented-Out Job Outputs

The commented-out build-test-push job (lines 40-48 in .github/workflows/build.yml) defines outputs (migrations_docker_version and activitypub_docker_version) that appear to be expected by subsequent steps (e.g., during Terraform apply operations). However, our initial automated search did not conclusively reveal references to these outputs within the repository.

Before proceeding, please manually verify whether downstream steps (in Terraform configurations or other workflow files) depend on these outputs. If they do, consider either re-enabling the build-test-push job or updating the dependent steps to source these values from a valid alternative.

Comment thread .github/workflows/build.yml Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (2)
.github/workflows/build.yml (2)

168-174: 🛠️ Refactor suggestion

Update Checkout Action Version for Terraform Repo
Similarly, the "Checkout terraform repo" step is still using actions/checkout@v3. Upgrading to actions/checkout@v4 will align with current best practices and static analysis recommendations.

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.4)

170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


160-166: 🛠️ Refactor suggestion

Update Checkout Action Version for activitypub-infra Repository
The "Checkout activitypub-infra repo" step uses actions/checkout@v3, which is outdated. It is recommended to update to actions/checkout@v4 for better performance and compatibility.

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.4)

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🧹 Nitpick comments (1)
.github/workflows/build.yml (1)

150-158: Enhance Shell Script Robustness by Quoting Variables
Within the label check, the condition

if [ $LABEL_NAMES != "" ]; then

should quote the variable to safeguard against cases when it is empty. This will prevent potential shell errors.

-          if [ $LABEL_NAMES != "" ]; then
+          if [ "$LABEL_NAMES" != "" ]; then
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d553386 and 50f5685.

📒 Files selected for processing (1)
  • .github/workflows/build.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/build.yml

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


212-212: property "build-test-push" is not defined in object type {}

(expression)

Comment thread .github/workflows/build.yml Outdated
Comment thread .github/workflows/build.yml Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
.github/workflows/build.yml (2)

160-163: 🛠️ Refactor suggestion

Upgrade Checkout Action for activitypub-infra Repository

The checkout step is using actions/checkout@v3, which has been flagged as outdated. Upgrading to actions/checkout@v4 is recommended for reliability and compatibility.

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.4)

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


168-171: 🛠️ Refactor suggestion

Upgrade Checkout Action for Terraform Repository

Similarly, the checkout step for the Terraform repository is still using actions/checkout@v3. Please update it to actions/checkout@v4:

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.4)

170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🧹 Nitpick comments (1)
.github/workflows/build.yml (1)

145-158: Quote Environment Variable in Label Check

In the step that checks for matching labels, the if-condition currently reads:

if [ $LABEL_NAMES != "" ]; then

To avoid potential issues when $LABEL_NAMES is empty or contains spaces, it’s best to quote the variable:

-          if [ $LABEL_NAMES != "" ]; then
+          if [ "$LABEL_NAMES" != "" ]; then
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 50f5685 and a5df5eb.

📒 Files selected for processing (1)
  • .github/workflows/build.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/build.yml

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


211-211: property "build-test-push" is not defined in object type {}

(expression)

🔇 Additional comments (7)
.github/workflows/build.yml (7)

138-142: Job Definition for deploy-pr Looks Good

The new deploy-pr job is correctly defined with the appropriate conditions for pull request events. However, please ensure that the intended behavior regarding dependency outputs is consistent throughout the workflow.


176-181: Terraform Version Retrieval Step Validation

The "Get terraform version" step correctly retrieves the version from the specified file using:

cat activitypub-infra/infrastructure/activitypub-staging-environments/.terraform-version

This step appears to be correct and consistent with expectations.


182-187: Terraform Setup Step is Correct

The step using hashicorp/setup-terraform@v3 with the interpolated terraform version is properly configured.


188-194: Module URL Replacement Implementation is Sound

Changing GitHub URL references with sed to point to local directories and adjusting backend prefixes is implemented correctly. No issues noted.


196-202: GCP Authentication Step is Correct

The authentication with GCP via google-github-actions/auth@v2 is properly set up with the required inputs.


203-208: Terraform Init Step is Implemented Correctly

The steps for initializing Terraform in the designated directory are clear and correct.


220-225: Load Balancer Update Step is Clear

The steps to update the load balancer using gcloud compute url-maps export are implemented correctly.

Comment thread .github/workflows/build.yml Outdated
closes https://linear.app/ghost/issue/AP-976

- Create ephemeral staging environment on PR labels *.ghost.is
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (2)
.github/workflows/build.yml (2)

160-167: 🛠️ Refactor suggestion

Update Checkout Action Version for activitypub-infra Repo
The step for checking out the activitypub-infra repo uses actions/checkout@v3, which is flagged as outdated. Upgrading to actions/checkout@v4 will improve reliability. Consider applying the following diff:

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.4)

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


168-175: 🛠️ Refactor suggestion

Update Checkout Action Version for Terraform Repo
Similarly, the checkout step for the terraform repo also uses actions/checkout@v3. It is advisable to update this to version v4 for consistency and to meet best practices. For example:

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.4)

170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🧹 Nitpick comments (4)
.github/workflows/build.yml (4)

145-158: Quote Shell Variables in the Label Check Step
In the shell conditional on line 152, the variable expansion of LABEL_NAMES is unquoted. To prevent potential issues (especially with empty strings or values containing spaces), it’s recommended to use quotes, e.g.,

-          if [ $LABEL_NAMES != "" ]; then
+          if [ "$LABEL_NAMES" != "" ]; then

188-195: Verify Variable Substitution in Sed Command
The step that changes module URLs uses a sed command on line 194:

sed -i 's/REPLACE_ME/${{ github.event.pull_request.number }}/g' terraform.tf

Ensure that the GitHub Actions YAML engine correctly substitutes the PR number in this context. In some cases, using double quotes around the sed expression might be necessary for proper substitution. Please verify that the intended PR number appears in the resulting file.


209-219: Terraform Apply Step Uses Static Docker Tags
The terraform apply step exports docker image environment variables with static :edge tags. Please confirm that using these static tags is the intended design now that the outputs from the previously defined (but commented out) build-test-push job are no longer available. If dynamic versioning is required, consider parameterizing these values in the future.


229-345: Clean Up Commented-Out Jobs if No Longer Needed
There remains a significant amount of commented-out code for jobs such as lint, check-yarn-lock, build-test-push, and the deployment jobs. If these are deprecated in favor of the new ephemeral staging workflow, consider removing them to reduce clutter and avoid any confusion in the future.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a5df5eb and 1842070.

📒 Files selected for processing (1)
  • .github/workflows/build.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/build.yml

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (6)
.github/workflows/build.yml (6)

138-142: Ephemeral Staging Deploy Job Definition Looks Good
The new deploy-pr job is well defined with a clear condition for pull request events. The environment and runner configuration match the intended usage for ephemeral staging environments.


176-180: Terraform Version Retrieval Step Looks Correct
The step correctly references the file activitypub-infra/infrastructure/activitypub-staging-environments/.terraform-version. No issues were identified here.


182-187: Terraform Setup Step is Properly Configured
The use of the output from the terraform-version step in the setup-terraform action is correct and follows the GitHub Actions expression syntax.


196-202: GCP Authentication Step is Configured Correctly
The authentication step correctly sets up access using the specified service account. No changes are needed here.


203-208: Terraform Initialization is Straightforward
The terraform init step properly changes directory and initializes Terraform. This step is clear and efficient.


223-228: Load Balancer Update Step Looks Good
The step to export and display the current URL maps is clear and straightforward. No issues detected.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
.github/workflows/build.yml (2)

160-167: 🛠️ Refactor suggestion

Upgrade Checkout Action Version for ActivityPub Infra Repository

The step "Checkout activitypub-infra repo" is currently using actions/checkout@v3, which is flagged by static analysis as outdated. Upgrading to actions/checkout@v4 will improve reliability and performance. For example:

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.4)

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


168-175: 🛠️ Refactor suggestion

Upgrade Checkout Action Version for Terraform Repository

Similarly, update the checkout step for the terraform repository from actions/checkout@v3 to actions/checkout@v4:

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4
🧰 Tools
🪛 actionlint (1.7.4)

170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🧹 Nitpick comments (2)
.github/workflows/build.yml (2)

138-144: Verify New deploy-pr Job Configuration and Dependency Management

The new deploy-pr job is well defined with a clear conditional trigger for pull request events and an appropriate environment. However, note that the needs: [build-test-push] dependency is commented out. Please double-check that this omission is intentional and that no outputs from the build-test-push job are required downstream in this job.


145-158: Improve Label Check Safety in Shell Script

In the "Check if any label matches *.ghost.is" step, the condition:

if [ $LABEL_NAMES != "" ]; then

could lead to word-splitting issues when LABEL_NAMES is empty or contains spaces. Consider replacing it with a more robust test:

-          if [ $LABEL_NAMES != "" ]; then
+          if [ -n "$LABEL_NAMES" ]; then

This adjustment ensures proper behavior regardless of the variable content.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1842070 and 338a091.

📒 Files selected for processing (1)
  • .github/workflows/build.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/build.yml

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (1)
.github/workflows/build.yml (1)

209-218: Confirm Hardcoded 'edge' Image Tags in Terraform Apply Step

In the "Terraform apply" step, environment variables for Docker images are exported with a hardcoded edge tag:

export TF_VAR_migrations_image=europe-docker.pkg.dev/ghost-activitypub/activitypub/migrations:edge
export TF_VAR_api_image=europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:edge
export TF_VAR_queue_image=europe-docker.pkg.dev/ghost-activitypub/activitypub/activitypub:edge

Please verify that using the edge tag is intentional for ephemeral staging environments. If a dynamic or versioned tag is desired, consider modifying these assignments accordingly.

Comment thread .github/workflows/build.yml Outdated
Comment on lines 188 to 107
- name: "Change github.com url in modules to local directories and add backend prefix"
if: ${{ steps.check-labels.outputs.is_ephemeral_staging == 'true' }}
run: |
cd activitypub-infra/infrastructure/activitypub-staging-environments
sed -i 's/github\.com\/TryGhost/\.\.\/\.\.\/\.\./gI' main.tf
sed -i 's/\?ref=main//g' main.tf
sed -i 's/REPLACE_ME/${{ github.event.pull_request.number }}/g' terraform.tf

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

Ensure Correct Sed Substitution for GitHub Expression

In the "Change github.com url in modules…" step, the sed command on line 193 uses single quotes:

sed -i 's/REPLACE_ME/${{ github.event.pull_request.number }}/g' terraform.tf

Since single quotes inhibit shell interpolation, the GitHub Actions expression may not be expanded as intended. Consider using double quotes:

-          sed -i 's/REPLACE_ME/${{ github.event.pull_request.number }}/g' terraform.tf
+          sed -i "s/REPLACE_ME/${{ github.event.pull_request.number }}/g" terraform.tf

This change should ensure that the PR number is correctly substituted in terraform.tf.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
.github/workflows/build.yml (1)

193-193: 🛠️ Refactor suggestion

Use double quotes for sed substitution to interpolate PR number

The sed command uses single quotes, which prevent shell/GitHub Actions expression interpolation. Use double quotes to ensure ${{ github.event.pull_request.number }} is correctly substituted:

-          sed -i 's/REPLACE_ME/${{ github.event.pull_request.number }}/g' terraform.tf
+          sed -i "s/REPLACE_ME/${{ github.event.pull_request.number }}/g" terraform.tf
🧹 Nitpick comments (1)
.github/workflows/build.yml (1)

151-151: Quote shell variable in conditional for robustness

The conditional if [ $LABEL_NAMES != "" ]; then may fail if $LABEL_NAMES is unset or contains spaces. For safer shell scripting, quote the variable:

-          if [ $LABEL_NAMES != "" ]; then
+          if [ "$LABEL_NAMES" != "" ]; then
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 338a091 and 38fa261.

📒 Files selected for processing (1)
  • .github/workflows/build.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/build.yml

161-161: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


169-169: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (1)
.github/workflows/build.yml (1)

138-227: Ephemeral staging deployment logic is sound and aligns with PR objectives

The new deploy-pr job correctly implements ephemeral staging environments, conditionally deploying based on PR labels and using infrastructure as code best practices. Previous issues with undefined outputs and variable naming have been addressed. The use of hardcoded Docker image tags is acceptable for ephemeral environments.

🧰 Tools
🪛 actionlint (1.7.4)

161-161: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


169-169: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 38fa261 and 7546051.

📒 Files selected for processing (1)
  • .github/workflows/build.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/build.yml

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (1)
.github/workflows/build.yml (1)

138-345: Ephemeral staging workflow logic looks solid

The new deploy-pr job and its conditional logic for ephemeral staging environments are well-structured and align with the PR objectives. Previous issues with output variables, path typos, and undefined dependencies have been addressed. The workflow now provides a clear, maintainable, and flexible approach for PR-based ephemeral deployments.

🧰 Tools
🪛 actionlint (1.7.4)

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
.github/workflows/build.yml (1)

194-194: 🛠️ Refactor suggestion

Fix shell interpolation for PR number substitution in sed command.

The sed command for replacing REPLACE_ME with the PR number uses single quotes, which prevents shell interpolation of ${{ github.event.pull_request.number }}. Use double quotes to ensure the PR number is correctly substituted.

-          sed -i 's/REPLACE_ME/${{ github.event.pull_request.number }}/g' terraform.tf
+          sed -i "s/REPLACE_ME/${{ github.event.pull_request.number }}/g" terraform.tf
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7546051 and b5fbfb4.

📒 Files selected for processing (1)
  • .github/workflows/build.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/build.yml

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (1)
.github/workflows/build.yml (1)

138-228: Ephemeral staging deployment logic is well-structured and aligns with PR objectives.

The new deploy-pr job correctly implements conditional ephemeral staging deployments based on PR labels, checks out required repos, sets up Terraform, and applies infrastructure changes. This approach improves flexibility and supports modern development workflows.

🧰 Tools
🪛 actionlint (1.7.4)

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
.github/workflows/build.yml (1)

194-194: 🛠️ Refactor suggestion

Fix PR number substitution in sed command

The sed command for substituting the PR number uses single quotes, which prevents GitHub Actions expressions from being interpolated. Use double quotes to ensure the PR number is correctly substituted in terraform.tf.

-          sed -i 's/REPLACE_ME/${{ github.event.pull_request.number }}/g' terraform.tf
+          sed -i "s/REPLACE_ME/${{ github.event.pull_request.number }}/g" terraform.tf
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b5fbfb4 and 0c5a089.

📒 Files selected for processing (1)
  • .github/workflows/build.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/build.yml

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🔇 Additional comments (1)
.github/workflows/build.yml (1)

138-239: Ephemeral staging workflow logic looks solid

The new deploy-pr job is well-structured, conditionally triggered, and implements ephemeral staging environments as described in the PR objectives. The use of hardcoded edge tags for Docker images is reasonable for temporary environments. No critical issues found in the overall workflow logic.

🧰 Tools
🪛 actionlint (1.7.4)

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Comment thread .github/workflows/build.yml Outdated
uses: docker/metadata-action@v5
- name: "Checkout activitypub-infra repo"
if: ${{ steps.check-labels.outputs.is_ephemeral_staging == 'true' }}
uses: actions/checkout@v3
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

Upgrade actions/checkout to v4 for compatibility and security

Both the "Checkout activitypub-infra repo" and "Checkout terraform repo" steps use actions/checkout@v3, which is outdated and flagged by static analysis. Upgrade to actions/checkout@v4 for continued compatibility and improved security.

-        uses: actions/checkout@v3
+        uses: actions/checkout@v4

[static_analysis]

Also applies to: 170-170

🧰 Tools
🪛 actionlint (1.7.4)

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
.github/workflows/cd-staging-environments.yml (1)

1-112: Well-structured workflow for ephemeral staging environments.

The workflow is thoughtfully designed, conditionally deploying ephemeral environments based on PR labels, and integrates well with Terraform and GCP. The use of label gating, dynamic Terraform versioning, and PR-specific resource naming is robust.

Consider documenting the teardown process for these ephemeral environments, and optionally add error handling or notifications for failed applies to improve maintainability and developer experience.

🧰 Tools
🪛 actionlint (1.7.4)

37-37: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


45-45: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c5a089 and 7d3580e.

📒 Files selected for processing (2)
  • .github/workflows/build.yml (2 hunks)
  • .github/workflows/cd-staging-environments.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/build.yml
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/cd-staging-environments.yml

37-37: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


45-45: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


- name: "Checkout activitypub-infra repo"
if: ${{ steps.check-labels.outputs.is_ephemeral_staging == 'true' }}
uses: actions/checkout@v3
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

Update actions/checkout to v4 for compatibility.

Static analysis indicates that actions/checkout@v3 is too old for the current GitHub Actions runner. Please update both usages to actions/checkout@v4 to ensure compatibility and receive the latest security and performance improvements.

-uses: actions/checkout@v3
+uses: actions/checkout@v4

Also applies to: 45-45

🧰 Tools
🪛 actionlint (1.7.4)

37-37: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
.github/workflows/cicd.yml (2)

188-195: Terraform config mutation: ensure idempotency and error handling

The step that modifies main.tf and terraform.tf uses sed to replace URLs and a placeholder. This is potentially brittle:

  • If the step is re-run, repeated sed replacements could corrupt the files.
  • No error handling is present if the files or patterns are missing.

Consider:

  • Backing up the files before mutation.
  • Using sed -i.bak and restoring from backup on failure.
  • Adding set -e at the top of the script to fail fast on errors.

Optionally, check that the replacements actually occur and fail if not.


138-371: Commented-out jobs: keep configuration up to date

Most jobs (lint, build, deploy-staging, deploy-production) are commented out. While this is fine for incremental rollout, ensure that:

  • The commented code is kept in sync with the active workflow.
  • Any secrets or environment variables referenced are still valid.
  • The team is aware of which jobs are intentionally disabled.

Consider adding a comment at the top of the file explaining the rationale for the commented-out jobs and the plan for re-enabling them.

🧰 Tools
🪛 actionlint (1.7.4)

138-138: "steps" section is missing in job "deploy-pr"

(syntax-check)


138-138: "runs-on" section is missing in job "deploy-pr"

(syntax-check)


138-138: "deploy-pr" job should not be empty. please remove this section if it's unnecessary

(syntax-check)


139-139: "steps" section is missing in job "if"

(syntax-check)


139-139: "runs-on" section is missing in job "if"

(syntax-check)


139-139: "if" job is scalar node but mapping node is expected

(syntax-check)


140-140: "steps" section is missing in job "name"

(syntax-check)


140-140: "runs-on" section is missing in job "name"

(syntax-check)


140-140: "name" job is scalar node but mapping node is expected

(syntax-check)


141-141: "steps" section is missing in job "runs-on"

(syntax-check)


141-141: "runs-on" section is missing in job "runs-on"

(syntax-check)


141-141: "runs-on" job is scalar node but mapping node is expected

(syntax-check)


143-143: "steps" section is missing in job "environment"

(syntax-check)


143-143: "runs-on" section is missing in job "environment"

(syntax-check)


143-143: "environment" job is scalar node but mapping node is expected

(syntax-check)


144-144: "steps" section is missing in job "steps"

(syntax-check)


144-144: "runs-on" section is missing in job "steps"

(syntax-check)


145-145: "steps" job is sequence node but mapping node is expected

(syntax-check)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d3580e and 8d4de49.

📒 Files selected for processing (2)
  • .github/workflows/build.yml (0 hunks)
  • .github/workflows/cicd.yml (1 hunks)
💤 Files with no reviewable changes (1)
  • .github/workflows/build.yml
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/cicd.yml

138-138: "steps" section is missing in job "deploy-pr"

(syntax-check)


138-138: "runs-on" section is missing in job "deploy-pr"

(syntax-check)


138-138: "deploy-pr" job should not be empty. please remove this section if it's unnecessary

(syntax-check)


139-139: "steps" section is missing in job "if"

(syntax-check)


139-139: "runs-on" section is missing in job "if"

(syntax-check)


139-139: "if" job is scalar node but mapping node is expected

(syntax-check)


140-140: "steps" section is missing in job "name"

(syntax-check)


140-140: "runs-on" section is missing in job "name"

(syntax-check)


140-140: "name" job is scalar node but mapping node is expected

(syntax-check)


141-141: "steps" section is missing in job "runs-on"

(syntax-check)


141-141: "runs-on" section is missing in job "runs-on"

(syntax-check)


141-141: "runs-on" job is scalar node but mapping node is expected

(syntax-check)


143-143: "steps" section is missing in job "environment"

(syntax-check)


143-143: "runs-on" section is missing in job "environment"

(syntax-check)


143-143: "environment" job is scalar node but mapping node is expected

(syntax-check)


144-144: "steps" section is missing in job "steps"

(syntax-check)


144-144: "runs-on" section is missing in job "steps"

(syntax-check)


145-145: "steps" job is sequence node but mapping node is expected

(syntax-check)

Comment thread .github/workflows/cicd.yml Outdated
Comment thread .github/workflows/cicd.yml
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
.github/workflows/cicd.yml (2)

150-158: 🛠️ Refactor suggestion

Label check logic: use robust string check for empty variables

The current check [ $LABEL_NAMES != "" ] is fragile and may fail if LABEL_NAMES is unset or empty, especially in strict shells. For robustness, quote the variable and use -n:

- if [ $LABEL_NAMES != "" ]; then
+ if [ -n "$LABEL_NAMES" ]; then

This prevents unbound variable errors and is the recommended shell idiom.


233-254: 🛠️ Refactor suggestion

Load balancer update: ensure atomicity, error handling, and cleanup

This step exports the URL map, modifies it with yq, but does not re-import the config to GCP, lacks error handling, and leaves temp files behind. For a robust and atomic update:

  • Add set -e at the top for error handling.
  • After modifying, re-import the config with gcloud compute url-maps import ... to apply changes.
  • Clean up temporary files (config.yml.tmp).
  • If this is only a preview, clarify intent in a comment.

Example improvement:

set -e
gcloud compute url-maps export stg-activitypub --global --project ghost-activitypub > config.yml
# ... yq logic ...
cp config.yml.tmp config.yml
gcloud compute url-maps import stg-activitypub --global --project ghost-activitypub --source=config.yml
rm -f config.yml.tmp
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8d4de49 and 502acc1.

📒 Files selected for processing (1)
  • .github/workflows/cicd.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/cicd.yml

162-162: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


170-170: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
.github/workflows/cicd.yml (2)

149-162: 🛠️ Refactor suggestion

Label check logic: quote variables for safety

The label check step uses [ $LABEL_NAMES != "" ], which can fail if $LABEL_NAMES is unset or contains spaces. For robustness, quote the variable and use -n:

- if [ $LABEL_NAMES != "" ]; then
+ if [ -n "$LABEL_NAMES" ]; then

This prevents errors in strict shells and with empty or multi-word label lists.


237-295: 🛠️ Refactor suggestion

Improve error handling and cleanup in Load Balancer update step

The load balancer update step performs several file operations and external commands (gcloud, yq, jq, mktemp). For reliability and maintainability:

  • Add set -euo pipefail at the top to fail on errors, unset variables, or pipeline failures.
  • Clean up temporary files created by mktemp after use.
  • Check for errors after critical commands (e.g., gcloud, yq).
  • Consider using trap to ensure cleanup even if the script fails.

Example improvements:

+ set -euo pipefail
...
- HEADER_MATCHES_YAML=$(mktemp)
+ HEADER_MATCHES_YAML=$(mktemp)
...
- ROUTE_RULE=$(mktemp)
+ ROUTE_RULE=$(mktemp)
...
# After use:
+ rm -f "$HEADER_MATCHES_YAML" "$ROUTE_RULE"

This will make the deployment step more robust and prevent resource leaks.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c40105a and 4fc1db0.

📒 Files selected for processing (1)
  • .github/workflows/cicd.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/cicd.yml

166-166: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


174-174: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
.github/workflows/cicd.yml (1)

149-162: 🛠️ Refactor suggestion

Label check logic: ensure robust handling of empty or unset variables

The label check step uses jq to extract label names and checks [ $LABEL_NAMES != "" ]. This can fail if $LABEL_NAMES is unset or empty, especially in strict shells. For robustness, quote the variable and use -n:

- if [ $LABEL_NAMES != "" ]; then
+ if [ -n "$LABEL_NAMES" ]; then

This prevents unbound variable errors and ensures correct behavior when no matching labels are present.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4fc1db0 and 689270c.

📒 Files selected for processing (1)
  • .github/workflows/cicd.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/cicd.yml

166-166: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


174-174: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Comment thread .github/workflows/cicd.yml
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
.github/workflows/cicd.yml (1)

155-168: Label check logic is robust and safe.

The label check step correctly uses jq to extract PR labels and checks for matches to *.ghost.is. The use of if [ $LABEL_NAMES != "" ]; was previously flagged as unsafe if $LABEL_NAMES is unset, but this has been addressed in a past review. Ensure the variable is always quoted ([ -n "$LABEL_NAMES" ]) to avoid unbound variable errors in strict shells.

🧹 Nitpick comments (2)
.github/workflows/cicd.yml (2)

243-273: Load balancer update: error handling, atomicity, and cleanup

The load balancer update step exports, modifies, and prepares to re-import the URL map. This logic is robust and follows best practices, as previously discussed:

  • Temporary files are used for atomic updates.
  • Unnecessary fields are deleted.
  • Host rules and path matchers are ensured.
  • Route rules are updated based on PR labels.

Suggestions:

  • Add set -euo pipefail at the top of the script for strict error handling.
  • Explicitly clean up temporary files (e.g., config.yml.tmp) at the end of the step.
  • Add a comment clarifying that the import step is intentionally commented out for preview/testing, and should be enabled for production.

1-390: General workflow structure and future-proofing

The overall workflow is well-structured for future expansion. Most jobs are commented out, focusing current execution on ephemeral staging deployments. When re-enabling jobs (lint, build, deploy-staging, deploy-production), ensure:

  • All action versions are up to date (e.g., actions/checkout@v4).
  • Any new steps follow the same error handling and atomicity standards as the active steps.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e0b9a0c and 4a365bf.

📒 Files selected for processing (1)
  • .github/workflows/cicd.yml (1 hunks)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
.github/workflows/cicd.yml (1)

162-162: 🛠️ Refactor suggestion

Label check logic: use robust string test to avoid shell errors

The label check uses [ $LABEL_NAMES != "" ], which can fail if $LABEL_NAMES is unset or empty. Use [ -n "$LABEL_NAMES" ] for a safe, POSIX-compliant check:

- if [ $LABEL_NAMES != "" ]; then
+ if [ -n "$LABEL_NAMES" ]; then

This prevents unbound variable errors and works even if no labels are present.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 29aa207 and 85209a8.

📒 Files selected for processing (1)
  • .github/workflows/cicd.yml (1 hunks)
🔇 Additional comments (2)
.github/workflows/cicd.yml (2)

277-277: Config not re-imported: clarify intent or uncomment import step

The script modifies the load balancer config but does not re-import it into GCP (the import step is commented out). If the intent is to apply changes, uncomment the import command:

# gcloud compute url-maps import stg-activitypub --source=config.yml --global --project ${GCP_PROJECT} --quiet

If this is only a preview, clarify with a comment.


26-26: actions/checkout@v4: Good use of latest version

The workflow uses actions/checkout@v4, which is the recommended and secure version.

Also applies to: 38-38, 59-59

Comment thread .github/workflows/cicd.yml Outdated
Comment thread .github/workflows/cicd.yml Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (3)
.github/workflows/cicd.yml (3)

274-274: ⚠️ Potential issue

YAML update: fix typo in yq command for routeAction

The yq command at this line has a typo: routeAction.weightedBackendServices: [...] is invalid YAML. It should be:

- "routeAction.weightedBackendServices: [ { \"backendService\": \"...\", \"weight\": 100 } ]"
+ "routeAction: { weightedBackendServices: [ { \"backendService\": \"...\", \"weight\": 100 } ] }"

Update the yq command to use the correct YAML structure for routeAction.


155-168: 🛠️ Refactor suggestion

Label check logic: quote variables and use -n for robustness

The label check step uses [ $LABEL_NAMES != "" ], which can fail if $LABEL_NAMES is unset or empty, especially with set -u or stricter shells. For safety and clarity, quote the variable and use -n:

- if [ $LABEL_NAMES != "" ]; then
+ if [ -n "$LABEL_NAMES" ]; then

This prevents unbound variable errors and is more idiomatic in shell scripts.


243-279: 🛠️ Refactor suggestion

Load balancer update: fix YAML structure, add error handling, and clean up temp files

  1. The yq command at line 274 has a typo in the YAML structure for routeAction. It should be:
  • "routeAction": {"weightedBackendServices: [ ... ] }
  • "routeAction": { "weightedBackendServices": [ ... ] }
    This ensures the YAML is valid and matches the expected GCP schema.
    
    
  1. Add set -euo pipefail at the top of the script to fail fast on errors, avoid unset variables, and catch pipeline failures.

  2. Use trap to clean up temporary files (e.g., config.yml.tmp) even if the script fails.

  3. Consider adding comments to clarify each block's intent for maintainability.

Suggested changes:

+ set -euo pipefail
+ trap 'rm -f config.yml.tmp' EXIT
...
- yq '.pathMatchers[0].routeRules += [{"priority": '"$NEXT_PRIORITY"', "matchRules": [{"prefixMatch": "/", "headerMatches": '$HEADER_MATCHES'}], "routeAction": {"weightedBackendServices: [ { "backendService": "'"$PR_SERVICE"'", "weight": 100 } ] } }]' config.yml > config.yml.tmp
+ yq '.pathMatchers[0].routeRules += [{"priority": '"$NEXT_PRIORITY"', "matchRules": [{"prefixMatch": "/", "headerMatches": '$HEADER_MATCHES'}], "routeAction": { "weightedBackendServices": [ { "backendService": "'"$PR_SERVICE"'", "weight": 100 } ] } }]' config.yml > config.yml.tmp

These changes will make the deployment more robust and easier to debug.

🧹 Nitpick comments (1)
.github/workflows/cicd.yml (1)

172-174: Update actions/checkout to v4 for compatibility and security

The commented-out steps use actions/checkout@v3. Update these to actions/checkout@v4 to ensure compatibility with the latest GitHub Actions runners and benefit from security updates.

- uses: actions/checkout@v3
+ uses: actions/checkout@v4

Also applies to: 180-182

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 85209a8 and a17e30c.

📒 Files selected for processing (1)
  • .github/workflows/cicd.yml (1 hunks)

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
.github/workflows/cicd.yml (1)

162-162: 🛠️ Refactor suggestion

Quote shell variables and use -n for robust empty checks in shell scripts.

The conditional if [ $LABEL_NAMES != "" ]; then is unsafe if $LABEL_NAMES is unset or empty, which can cause errors in strict shells. Use [ -n "$LABEL_NAMES" ] instead, and always quote shell variables in conditionals.

- if [ $LABEL_NAMES != "" ]; then
+ if [ -n "$LABEL_NAMES" ]; then

This prevents unbound variable errors and is a best practice for shell scripting.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a17e30c and c9d77a5.

📒 Files selected for processing (1)
  • .github/workflows/cicd.yml (1 hunks)
🔇 Additional comments (1)
.github/workflows/cicd.yml (1)

1-392: Overall workflow structure and ephemeral staging logic look good.

The workflow is well-structured, aligns with the PR objective of ephemeral staging environments, and uses modern GitHub Actions and GCP authentication patterns. The commented-out jobs provide a clear path for future expansion.

Once the above shell script improvements are made, the workflow will be robust and production-ready.

Comment on lines +249 to +273
# Get current config
gcloud compute url-maps export stg-activitypub --global --project ${GCP_PROJECT} > config.yml
# Delete unnecessary fields
yq 'del(.fingerprint)' config.yml -i
yq 'del(.creationTimestamp)' config.yml -i
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 '.hostRules = (.hostRules // [{"hosts": ["activitypub.infra.ghost.is"], "pathMatcher": "staging-environments"}])' config.yml > config.yml.tmp
yq '.hostRules = ([{"hosts": ["activitypub.infra.ghost.is"], "pathMatcher": "staging-environments"}])' config.yml > config.yml.tmp
mv config.yml.tmp config.yml
yq '.pathMatchers = (.pathMatchers // [{"name": "staging-environments", "defaultService": "'"$DEFAULT_SERVICE"'", "routeRules": []}])' config.yml > config.yml.tmp
yq '.pathMatchers = ([{"name": "staging-environments", "defaultService": "'"$DEFAULT_SERVICE"'", "routeRules": []}])' config.yml > config.yml.tmp
mv config.yml.tmp config.yml
# Remove existing route rules for the PR service
yq '.pathMatchers[] |= (.routeRules |= map(select((.routeAction.weightedBackendServices // []) | length == 0 or .routeAction.weightedBackendServices[0].backendService != env(PR_SERVICE))))' config.yml > config.yml.tmp
mv config.yml.tmp 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 NEXT_PRIORITY=$((MAX_PRIORITY + 1))
export HEADER_MATCHES=$(echo "$LABELS" | jq -c '[.[] | select(.name | test("\\.ghost\\.is$")) | { "headerName": "X-Forwarded-Host", "exactMatch": "\(.name)" }'])
yq '.pathMatchers[0].routeRules += [{"priority": '"$NEXT_PRIORITY"', "matchRules": [{"prefixMatch": "/", "headerMatches": '$HEADER_MATCHES'}], "routeAction": {"weightedBackendServices": [ { "backendService": "'$PR_SERVICE'", "weight": 100 } ] } }]' config.yml > config.yml.tmp
mv config.yml.tmp config.yml
echo "Updating url map with:"
cat config.yml
gcloud compute url-maps import stg-activitypub --source=config.yml --global --project ${GCP_PROJECT} --quiet
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

Add robust error handling and cleanup to the load balancer update script.

For reliability, add set -euo pipefail at the top of the script to fail fast on errors, and a trap to clean up temporary files even if the script fails. This prevents silent failures and orphaned temp files.

Add these lines at the top of the run block:

set -euo pipefail
trap 'rm -f config.yml.tmp' EXIT

This will make the deployment more robust and easier to debug.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
.github/workflows/cicd.yml (1)

156-170: ⚠️ Potential issue

Harden label check logic for empty or unset variables

The label check step uses:

if [ $LABEL_NAMES != "" ]; then

This is fragile and can fail if LABEL_NAMES is unset or empty, especially with set -u or stricter shells. For robustness, always quote the variable and use -n:

- if [ $LABEL_NAMES != "" ]; then
+ if [ -n "$LABEL_NAMES" ]; then

This prevents unbound variable errors and is the recommended shell idiom.

Apply this diff to fix:

-          if [ $LABEL_NAMES != "" ]; then
+          if [ -n "$LABEL_NAMES" ]; then
🧹 Nitpick comments (1)
.github/workflows/cicd.yml (1)

277-289: "WIP" step: Consider clarifying intent and making PR number dynamic

The "WIP" step lists Cloud Run services and checks the state of PR 432 via gh pr view 432. This is hardcoded and will not work for other PRs. If the intent is to check the state of the current PR, use ${{ github.event.pull_request.number }} or similar.

Also, consider adding comments to clarify the purpose of this step for future maintainers.

Apply this diff to make the PR number dynamic:

-            gh pr view 432 --json state | jq -r '.state'
+            gh pr view $num --json state | jq -r '.state'
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c9d77a5 and 7d6d7e9.

📒 Files selected for processing (1)
  • .github/workflows/cicd.yml (1 hunks)
🔇 Additional comments (1)
.github/workflows/cicd.yml (1)

207-214: GCP authentication step is correct and follows best practices

The GCP authentication step uses workload identity and a dedicated service account for ephemeral staging environments. This is a secure and recommended approach for GitHub Actions workflows.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
.github/workflows/cicd.yml (1)

163-163: ⚠️ Potential issue

Quote shell variables in conditional checks for robustness

In the label check step, the conditional if [ $LABEL_NAMES != "" ]; should quote the variable to prevent errors if $LABEL_NAMES is unset or contains spaces. Use [ -n "$LABEL_NAMES" ] for a safe, POSIX-compliant check.

- if [ $LABEL_NAMES != "" ]; then
+ if [ -n "$LABEL_NAMES" ]; then

This prevents unbound variable errors and improves script reliability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b24484 and bb6739c.

📒 Files selected for processing (1)
  • .github/workflows/cicd.yml (5 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/cicd.yml

173-173: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


181-181: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build, Test and Push
🔇 Additional comments (3)
.github/workflows/cicd.yml (3)

245-275: Excellent: Load balancer update script is robust and follows best practices

The load balancer update step now includes proper error handling, atomic file operations, and re-imports the modified config. Temporary files are managed and the logic is clear. This addresses all previously raised concerns.


109-140: Conditional Docker push logic is correct and efficient

The conditional execution of GCP authentication, Artifact Registry login, and Docker image pushes ensures that these steps only run for relevant pull request actions. This optimizes workflow runs and avoids unnecessary operations.


149-243: Ephemeral staging deployment logic is well-structured

The new deploy-pr job is well-organized, with clear separation of label checking, repo checkouts, Terraform setup, GCP authentication, and deployment steps. The use of environment variables and conditional execution is appropriate.

🧰 Tools
🪛 actionlint (1.7.4)

173-173: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)


181-181: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

Comment thread .github/workflows/cicd.yml Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds ephemeral staging environments by updating the CICD workflow triggers, modifying job environments, and introducing a new deploy-pr job to conditionally deploy based on pull request labels.

  • Updated pull request event types and conditions in the workflow.
  • Changed the build-test-push job’s environment from "staging" to "build".
  • Added a deploy-pr job with label checking and load balancer updates for ephemeral staging.

Comment thread .github/workflows/cicd.yml Outdated
run: |
export LABEL_NAMES=$(echo "$LABELS" | jq -r '[.[] | select(.name | test("\\.ghost\\.is$")) | .name] | join(",")')
echo "Label names: $LABEL_NAMES"
if [ $LABEL_NAMES != "" ]; then
Copy link

Copilot AI Apr 16, 2025

Choose a reason for hiding this comment

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

Consider quoting $LABEL_NAMES (e.g. if [ "$LABEL_NAMES" != "" ]; then) to prevent word splitting or potential errors when the variable is empty.

Suggested change
if [ $LABEL_NAMES != "" ]; then
if [ "$LABEL_NAMES" != "" ]; then

Copilot uses AI. Check for mistakes.
Comment thread .github/workflows/cicd.yml Outdated
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 '.hostRules = (.hostRules // [{"hosts": ["activitypub.infra.ghost.is"], "pathMatcher": "staging-environments"}])' config.yml > config.yml.tmp
yq '.hostRules = ([{"hosts": ["activitypub.infra.ghost.is"], "pathMatcher": "staging-environments"}])' config.yml > config.yml.tmp
Copy link

Copilot AI Apr 16, 2025

Choose a reason for hiding this comment

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

The .hostRules field is being set consecutively (lines 258 and 259); if the duplication is not intentional, please remove the redundant command to avoid unexpected overwrites.

Suggested change
yq '.hostRules = ([{"hosts": ["activitypub.infra.ghost.is"], "pathMatcher": "staging-environments"}])' config.yml > config.yml.tmp

Copilot uses AI. Check for mistakes.
build-test-push:
name: Build, Test and Push
environment: staging
environment: build
Copy link

Copilot AI Apr 16, 2025

Choose a reason for hiding this comment

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

[nitpick] The build-test-push job’s environment was changed from 'staging' to 'build'. Please confirm that this alteration is intentional and does not inadvertently affect deployment behavior.

Suggested change
environment: build
environment: staging

Copilot uses AI. Check for mistakes.
closes https://linear.app/ghost/issue/AP-976

- Create ephemeral staging environment on PR labels *.ghost.is
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants