-
Notifications
You must be signed in to change notification settings - Fork 0
Comprehensive CI/CD Pipeline Improvements: Build Optimization, Lock File Validation, and Staging Cleanup #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
508ea5c
5ca823a
d85b3c1
1d3d71b
751779b
7482e1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,54 @@ jobs: | |
| sudo chown -R $(whoami) .git | ||
| sudo chmod -R u+w .git | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20.x' | ||
| cache: 'npm' | ||
|
|
||
| - name: Validate package-lock.json | ||
| id: validate-lockfile | ||
| run: | | ||
| echo "Validating lock file sync..." | ||
| if bash scripts/validate-lockfile.sh; then | ||
| echo "validation=success" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "validation=failed" >> $GITHUB_OUTPUT | ||
| echo "::error::Lock file validation failed. Please regenerate package-lock.json by running 'npm install'" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Install dependencies with retry | ||
| id: npm-install | ||
| run: | | ||
| MAX_ATTEMPTS=3 | ||
| ATTEMPT=1 | ||
|
|
||
| while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do | ||
| echo "π¦ Attempt $ATTEMPT of $MAX_ATTEMPTS: Running npm ci..." | ||
|
|
||
| if npm ci; then | ||
| echo "β npm ci succeeded" | ||
| exit 0 | ||
| else | ||
| echo "β npm ci failed on attempt $ATTEMPT" | ||
|
|
||
| if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then | ||
| echo "::error::npm ci failed after $MAX_ATTEMPTS attempts" | ||
| echo "::error::This might indicate:" | ||
| echo "::error:: 1. Lock file is out of sync (run validate-lockfile.sh locally)" | ||
| echo "::error:: 2. Network issues with npm registry" | ||
| echo "::error:: 3. Corrupted cache" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Retrying in 5 seconds..." | ||
| sleep 5 | ||
| ATTEMPT=$((ATTEMPT + 1)) | ||
| fi | ||
| done | ||
|
|
||
| - name: Build And Deploy | ||
| id: builddeploy | ||
| uses: Azure/static-web-apps-deploy@v1 | ||
|
Comment on lines
76
to
78
|
||
|
|
@@ -39,6 +87,15 @@ jobs: | |
| output_location: 'dist' # Built app content directory - optional | ||
| ###### End of Repository/Build Configurations ###### | ||
|
|
||
| - name: Deployment Summary | ||
| if: always() | ||
| run: | | ||
| echo "## π Deployment Summary" >> $GITHUB_STEP_SUMMARY | ||
| echo "" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Lock File Validation**: ${{ steps.validate-lockfile.outputs.validation }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **npm ci**: ${{ steps.npm-install.outcome }}" >> $GITHUB_STEP_SUMMARY | ||
| echo "- **Build and Deploy**: ${{ steps.builddeploy.outcome }}" >> $GITHUB_STEP_SUMMARY | ||
|
|
||
| close_pull_request_job: | ||
| if: github.event_name == 'pull_request' && github.event.action == 'closed' | ||
| runs-on: ubuntu-latest | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,158 @@ | ||||||
| name: Cleanup Staging Environments | ||||||
|
|
||||||
| on: | ||||||
| # Run weekly on Sundays at 2 AM UTC | ||||||
| schedule: | ||||||
| - cron: '0 2 * * 0' | ||||||
| # Allow manual trigger | ||||||
| workflow_dispatch: | ||||||
| inputs: | ||||||
| dry_run: | ||||||
| description: 'Dry run mode (show what would be deleted without deleting)' | ||||||
| required: false | ||||||
| default: 'false' | ||||||
| type: choice | ||||||
| options: | ||||||
| - 'true' | ||||||
| - 'false' | ||||||
|
|
||||||
| jobs: | ||||||
| cleanup-staging: | ||||||
| name: Clean up unused staging environments | ||||||
| runs-on: ubuntu-latest | ||||||
|
|
||||||
| steps: | ||||||
| - name: Checkout repository | ||||||
| uses: actions/checkout@v4 | ||||||
|
|
||||||
| - name: Azure Login | ||||||
| uses: azure/login@v2 | ||||||
|
||||||
| uses: azure/login@v2 | |
| uses: azure/login@v2.0.0 |
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SWA_NAME is hard-coded, which makes the workflow brittle if the resource name changes or multiple environments are used. Consider passing SWA_NAME and RESOURCE_GROUP as workflow inputs or env variables (defaulting via shell parameter expansion), so they can be configured without code changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fetch all open PRs before deciding deletions
The cleanup job relies on gh pr list --json number --jq '.[].number' to decide whether a staging environment belongs to an open pull request, but the commandβs default --limit is 30. Repositories with more than 30 open PRs will omit older ones from this list, so their environments will be treated as closed and deleted even though the PRs remain open. Pass an explicit --limit (or paginate) so every open PR is considered before deleting environments.
Useful? React with πΒ / π.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fetch all open PRs before deciding deletions
The cleanup job relies on
gh pr list --json number --jq '.[].number'to decide whether a staging environment belongs to an open pull request, but the commandβs default--limitis 30. Repositories with more than 30 open PRs will omit older ones from this list, so their environments will be treated as closed and deleted even though the PRs remain open. Pass an explicit--limit(or paginate) so every open PR is considered before deleting environments.Useful? React with πΒ / π.
@copilot Implement this as you see fit
Copilot
AI
Oct 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CLEANED and KEPT are incremented inside a while loop that's in a subshell due to the upstream pipe. Their final values will remain 0 outside the loop, producing an inaccurate summary. Fix by avoiding the pipeline, e.g., use process substitution: while read -r env; do ... done < <(jq -c '.[]' <<< "$ENVIRONMENTS").
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pin GitHub Actions to a full commit SHA to prevent supply-chain risks from tag changes. Example: uses: actions/setup-node@ with a comment for the pinned version.