Skip to content

edited preview files - #3571

Merged
Baalmart merged 1 commit into
stagingfrom
preview-fixes
Jun 3, 2026
Merged

edited preview files#3571
Baalmart merged 1 commit into
stagingfrom
preview-fixes

Conversation

@Psalmz777

@Psalmz777 Psalmz777 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes (What does this PR do?)

  • Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Status of maturity (all need to be checked before merging):

  • I've tested this locally
  • I consider this code done
  • This change ready to hit production in its current state
  • The title of the PR states what changed and the related issues number (used for the release note).
  • I've included issue number in the "Closes #ISSUE-NUMBER" part of the "What are the relevant tickets?" section to link the issue.
  • I've updated corresponding documentation for the changes in this PR.
  • I have written unit and/or e2e tests for my change(s).

How should this be manually tested?

  • Please include the steps to be done inorder to setup and test this PR.

What are the relevant tickets?

Screenshots (optional)

Summary by CodeRabbit

  • Chores
    • Improved PR preview deployment and cleanup processes with enhanced environment variable handling and streamlined Azure Container App removal logic for closed pull requests.

@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

These GitHub Actions workflows for Azure Container App previews are refactored to standardize branch-name sanitization, replace string-based environment variable passing with bash arrays, and consolidate cleanup logic from multiple conditional jobs into a single removal job.

Changes

Azure Preview Deployment Workflows

Layer / File(s) Summary
Branch-name sanitization output foundation
.github/workflows/deploy-frontend-azurepreview.yml, .github/workflows/remove-deploy-azurepreview.yml
Both workflows now expose a sanitized branch-name output derived from truncated/lowercased head reference, used consistently as the Container App name prefix.
Environment variable array refactoring for beacon, calibrate-app, and docs
.github/workflows/deploy-frontend-azurepreview.yml
Three services replace jq string-join with bash mapfile array loading, passing environment variables to az containerapp up via array expansion.
Analytics platform app naming and NextAuth environment variables
.github/workflows/deploy-frontend-azurepreview.yml
App naming switches to the sanitized branch output, environment variables are loaded via mapfile, and computed NextAuth configuration variables are explicitly appended before deployment.
Vertex domain and authentication computation reordering
.github/workflows/deploy-frontend-azurepreview.yml
DEFAULT_DOMAIN and NEXTAUTH_URL assignments move earlier in the script to be available for subsequent environment variable construction and auth status checks.
Consolidated preview cleanup logic
.github/workflows/remove-deploy-azurepreview.yml
Multiple per-service conditional removal jobs are replaced with a single remove-previews job that authenticates once and iterates over a fixed service list to delete matching Container Apps.

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly Related PRs

  • airqo-platform/AirQo-frontend#3568: Both PRs modify the same Azure preview workflows by adjusting branch-name sanitization and its usage in Container App naming for previews.

Suggested Labels

ready for review

Suggested Reviewers

  • Baalmart

Poem

🚀 Branch names now trimmed to elegant arrays,
Azure previews dance in more graceful ways,
One job cleans up what many did before,
Workflows lean, consistent, and refined to the core. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'edited preview files' is vague and does not clearly summarize the main changes, which involve refactoring preview deployment and removal workflows for Azure Container Apps. Use a more descriptive title that captures the key changes, such as 'Refactor Azure preview deployment and removal workflows' or 'Consolidate preview app management across services'.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch preview-fixes

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
.github/workflows/deploy-frontend-azurepreview.yml (1)

1-14: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add least-privilege permissions: for pull_request_target

This workflow has no top-level permissions: block, so GITHUB_TOKEN relies on repo/Actions defaults instead of being explicitly scoped for pull_request_target.

Suggested change
+permissions:
+  contents: read
+  issues: write
+
 env:
   RG: airqo-main-rg
   LOCATION: westeurope
   PR_PREVIEW_ENV: airqo-pr-preview-env
   REGISTRY_URL: airqoacr.azurecr.io
   KEYVAULT: airqo-kv-staging
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/deploy-frontend-azurepreview.yml around lines 1 - 14, The
workflow declared by name deploy-to-azure-preview-environment triggers on
pull_request_target and currently omits a top-level permissions block, so
GITHUB_TOKEN inherits default repo-level rights; add an explicit top-level
permissions: block scoped minimally for the actions used (for example setting
contents: write only if the job needs to write checks or packages, and id-token:
write only if OIDC is used, otherwise set write to none and set pull-request,
checks, contents, or id-token to read/write as strictly required) to ensure
least-privilege for GITHUB_TOKEN when running the pull_request_target event;
place this permissions: block at the top level of the workflow (alongside name
and on) and reference the pull_request_target-triggered jobs that need those
scopes to choose exact permission keys.
.github/workflows/remove-deploy-azurepreview.yml (2)

15-32: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fix the duplicated branch-name sanitization in remove-deploy-azurepreview.yml

  • remove-deploy-azurepreview.yml uses the same RAW:0:12 truncation as deploy-frontend-azurepreview.yml, and then deletes apps named ${BRANCH}-calibrate-app-preview (and others). With the Azure Container App name limit of 32 chars, 12 + "-calibrate-app-preview"(22) = 34, so cleanup can compute names that don’t match what Azure accepts/deployed.
  • The current “sanitizer” only truncates and strips trailing hyphens; it doesn’t enforce Azure Container App naming rules (lowercase letters/numbers/hyphens, no consecutive hyphens, start with a letter, end with alphanumeric).

Apply the same updated sanitizer/truncation logic used in the deploy workflow to this remove workflow so preview deletions target the correct app names.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/remove-deploy-azurepreview.yml around lines 15 - 32, The
branch-name sanitization in the remove workflow (job name "branch-name", step
"string" using ASzc/change-string-case-action@v5 and the "sanitize" step that
sets env RAW and uses CLEAN=$(printf '%s' "${RAW:0:12}" | sed 's/-*$//')) must
be replaced with the same sanitizer/truncation logic used in the deploy
workflow: compute the branch-segment length as 32 minus the preview suffix
length, enforce allowed characters (lowercase letters, digits, hyphens),
collapse consecutive hyphens, strip leading non-letters and trailing
non-alphanumerics, and trim to the computed length before emitting sanitized via
$GITHUB_OUTPUT; update the "sanitize" step to mirror the deploy workflow's
implementation so the generated branch names match Azure Container App naming
rules and the deployed app names used during cleanup.

1-12: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Drop GITHUB_TOKEN permissions entirely in this cleanup workflow (permissions: {})

This workflow doesn’t call the GitHub API (no checkout/github-script/gh/curl). It authenticates to Azure via azure/login@v2 using creds: ${{ secrets.AZURE_CREDENTIALS }} (secret-based auth), so no GitHub OIDC token permissions are needed.

Suggested change
+permissions: {}
+
 env:
   RG: airqo-main-rg
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/remove-deploy-azurepreview.yml around lines 1 - 12, The
workflow "name: remove-deploy-previews" currently doesn't need GitHub API
tokens; update the workflow to drop GITHUB_TOKEN permissions by adding a
top-level permissions: {} stanza (i.e., an empty permissions map) to the
workflow root, ensuring no default token scopes are granted; leave the existing
azure/login@v2 usage (creds: ${{ secrets.AZURE_CREDENTIALS }}) and env RG
intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/deploy-frontend-azurepreview.yml:
- Around line 27-30: Replace the mutable tag usage of the action
ASzc/change-string-case-action@v5 with a pinned full commit SHA: locate the step
using "uses: ASzc/change-string-case-action@v5" and update it to the action's
exact commit SHA (e.g., ASzc/change-string-case-action@<full-commit-sha>) so the
workflow is immutable; fetch the canonical commit SHA from the action's GitHub
repository and substitute it in place of `@v5`.

---

Outside diff comments:
In @.github/workflows/deploy-frontend-azurepreview.yml:
- Around line 1-14: The workflow declared by name
deploy-to-azure-preview-environment triggers on pull_request_target and
currently omits a top-level permissions block, so GITHUB_TOKEN inherits default
repo-level rights; add an explicit top-level permissions: block scoped minimally
for the actions used (for example setting contents: write only if the job needs
to write checks or packages, and id-token: write only if OIDC is used, otherwise
set write to none and set pull-request, checks, contents, or id-token to
read/write as strictly required) to ensure least-privilege for GITHUB_TOKEN when
running the pull_request_target event; place this permissions: block at the top
level of the workflow (alongside name and on) and reference the
pull_request_target-triggered jobs that need those scopes to choose exact
permission keys.

In @.github/workflows/remove-deploy-azurepreview.yml:
- Around line 15-32: The branch-name sanitization in the remove workflow (job
name "branch-name", step "string" using ASzc/change-string-case-action@v5 and
the "sanitize" step that sets env RAW and uses CLEAN=$(printf '%s' "${RAW:0:12}"
| sed 's/-*$//')) must be replaced with the same sanitizer/truncation logic used
in the deploy workflow: compute the branch-segment length as 32 minus the
preview suffix length, enforce allowed characters (lowercase letters, digits,
hyphens), collapse consecutive hyphens, strip leading non-letters and trailing
non-alphanumerics, and trim to the computed length before emitting sanitized via
$GITHUB_OUTPUT; update the "sanitize" step to mirror the deploy workflow's
implementation so the generated branch names match Azure Container App naming
rules and the deployed app names used during cleanup.
- Around line 1-12: The workflow "name: remove-deploy-previews" currently
doesn't need GitHub API tokens; update the workflow to drop GITHUB_TOKEN
permissions by adding a top-level permissions: {} stanza (i.e., an empty
permissions map) to the workflow root, ensuring no default token scopes are
granted; leave the existing azure/login@v2 usage (creds: ${{
secrets.AZURE_CREDENTIALS }}) and env RG intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fb17c242-3132-4c32-9032-801322a0cf16

📥 Commits

Reviewing files that changed from the base of the PR and between 7a70e44 and e2fee14.

📒 Files selected for processing (2)
  • .github/workflows/deploy-frontend-azurepreview.yml
  • .github/workflows/remove-deploy-azurepreview.yml

Comment on lines +27 to +30
- id: string
uses: ASzc/change-string-case-action@v5
with:
string: ${{ github.head_ref || github.ref_name }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show the workflow around the referenced lines
FILE=".github/workflows/deploy-frontend-azurepreview.yml"
echo "=== File: $FILE ==="
nl -ba "$FILE" | sed -n '1,120p'

Repository: airqo-platform/AirQo-frontend

Length of output: 199


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE=".github/workflows/deploy-frontend-azurepreview.yml"
echo "=== File: $FILE ==="

# Print with line numbers (nl not available)
awk '{printf "%5d\t%s\n", NR, $0}' "$FILE" | sed -n '1,120p'

echo "=== Matches for ASzc/change-string-case-action ==="
rg -n "ASzc/change-string-case-action@v" "$FILE" || true

Repository: airqo-platform/AirQo-frontend

Length of output: 4877


🌐 Web query:

GitHub Actions security secure use pin reusable actions to full commit SHA documentation

💡 Result:

Pinning GitHub Actions to a full-length commit SHA is considered the most secure way to consume an action as an immutable release [1][2]. Unlike version tags (e.g., @v1), which are mutable and can be moved or deleted by an actor who gains access to the action's repository, a full-length commit SHA uniquely identifies the exact code being executed, mitigating the risk of unauthorized malicious changes [1][3][4]. Key Security Considerations and Implementation: 1. Mandatory Pinning: GitHub documentation and security best practices emphasize that pinning to a full-length commit SHA is the only way to ensure immutability [1][2]. When using a SHA, you should verify it originates from the action's official repository rather than a fork, as GitHub resolves the SHA to a valid Git object regardless of the source repository [1][5]. 2. Enforcing Policies: Administrators can enforce SHA pinning at the organization or repository level through GitHub Actions policies [1][6][3]. When enabled, any workflow attempting to use an action not pinned to a full commit SHA will fail [6][3]. 3. Automating Maintenance: Manually updating SHAs is inefficient. Tools such as Dependabot, pinact, or other automation workflows are recommended to manage dependencies and keep pinned actions updated [1][3][4]. 4. Limitation with Reusable Workflows: While GitHub's native SHA-pinning enforcement applies primarily to actions, it is widely recommended to apply similar rigor to reusable workflows where possible [3]. Note that some tooling for SHA pinning may focus specifically on Actions [3]. 5. Additional Defenses: Pinning should be part of a broader security strategy, including: - Setting permissions: {} at the workflow level to follow the principle of least privilege [5][4]. - Auditing the source code of third-party actions [2]. - Using security tools like Scorecards or Zizmor to identify unpinned dependencies or risky supply chain practices [2][5][4]. For official configuration guidance, refer to the GitHub documentation on securing your workflows and the settings for managing allowed actions and reusable workflows [1][6].

Citations:


Pin ASzc/change-string-case-action to a full commit SHA (not @v5).

.github/workflows/deploy-frontend-azurepreview.yml (lines 27–30) uses ASzc/change-string-case-action@v5, which is mutable at the tag level; pinning to the action’s full commit SHA prevents upstream changes from altering what this privileged workflow runs. See: https://docs.github.com/en/actions/reference/security/secure-use

🧰 Tools
🪛 zizmor (1.25.2)

[error] 28-28: unpinned action reference (unpinned-uses): action is not pinned to a hash (required by blanket policy)

(unpinned-uses)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/deploy-frontend-azurepreview.yml around lines 27 - 30,
Replace the mutable tag usage of the action ASzc/change-string-case-action@v5
with a pinned full commit SHA: locate the step using "uses:
ASzc/change-string-case-action@v5" and update it to the action's exact commit
SHA (e.g., ASzc/change-string-case-action@<full-commit-sha>) so the workflow is
immutable; fetch the canonical commit SHA from the action's GitHub repository
and substitute it in place of `@v5`.

@Baalmart
Baalmart merged commit 85ed3ac into staging Jun 3, 2026
27 checks passed
@Baalmart
Baalmart deleted the preview-fixes branch June 3, 2026 08:00
@Baalmart Baalmart mentioned this pull request Jun 3, 2026
5 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Jul 1, 2026
7 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Jul 11, 2026
7 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Jul 20, 2026
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants