update: adding a lost image #2215
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # GitHub Actions Workflow: Sync Content to Strapi CMS (With Relations Support) | |
| # This workflow syncs content changes from specific data folders to Strapi CMS | |
| # Supports foreign key relations: tags, authors, related_faqs | |
| # Triggers: On labeled PR, on push to staging/main branches | |
| name: Sync Content to Strapi CMS | |
| on: | |
| pull_request: | |
| types: [labeled, synchronize, opened, reopened] | |
| paths: | |
| - 'data/**/*.mdx' | |
| - 'data/**/*.md' | |
| - 'data-assets/**' | |
| push: | |
| branches: | |
| - main # Configurable: Change to your production branch | |
| - staging # Configurable: Change to your staging branch | |
| paths: | |
| - 'data/**/*.mdx' | |
| - 'data/**/*.md' | |
| - 'data-assets/**' | |
| env: | |
| # Configurable: Array of folders to sync to CMS | |
| SYNC_FOLDERS: '["faqs", "case-study", "opentelemetry", "comparisons"]' | |
| # Strapi Configuration (production) | |
| CMS_API_URL: ${{ secrets.CMS_API_URL }} | |
| CMS_API_TOKEN: ${{ secrets.CMS_API_TOKEN }} | |
| # Strapi Configuration (staging) | |
| CMS_STAGING_API_URL: ${{ secrets.CMS_STAGING_API_URL }} | |
| CMS_STAGING_API_TOKEN: ${{ secrets.CMS_STAGING_API_TOKEN }} | |
| # Revalidation Configuration | |
| NEXT_PUBLIC_BASE_URL: ${{ secrets.NEXT_PUBLIC_BASE_URL }} | |
| NEXT_PUBLIC_STAGING_BASE_URL: ${{ secrets.NEXT_PUBLIC_STAGING_BASE_URL }} | |
| REVALIDATE_SECRET: ${{ secrets.REVALIDATE_SECRET }} | |
| # S3 Configuration | |
| S3_REGION: ${{ secrets.S3_REGION }} | |
| # Branch Configuration | |
| PRODUCTION_BRANCH: 'main' | |
| STAGING_BRANCH: 'staging' | |
| jobs: | |
| detect-changes: | |
| name: Detect Changed Files | |
| runs-on: ubuntu-latest | |
| outputs: | |
| any_changed: ${{ steps.changed-content.outputs.any_changed }} | |
| any_deleted: ${{ steps.changed-content.outputs.any_deleted }} | |
| any_assets_changed: ${{ steps.changed-assets.outputs.any_changed }} | |
| deployment_status: ${{ steps.determine-status.outputs.deployment_status }} | |
| should_sync: ${{ steps.check-sync.outputs.should_sync }} | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get Changed Content Files | |
| id: changed-content | |
| uses: tj-actions/changed-files@v46 | |
| with: | |
| files: | | |
| data/**/*.mdx | |
| data/**/*.md | |
| json: true | |
| escape_json: false | |
| write_output_files: true | |
| - name: Rename Content Output Files | |
| run: | | |
| if [ -f .github/outputs/all_changed_files.json ]; then | |
| mv .github/outputs/all_changed_files.json .github/outputs/content_changed_files.json | |
| else | |
| echo "[]" > .github/outputs/content_changed_files.json | |
| fi | |
| if [ -f .github/outputs/deleted_files.json ]; then | |
| mv .github/outputs/deleted_files.json .github/outputs/content_deleted_files.json | |
| else | |
| echo "[]" > .github/outputs/content_deleted_files.json | |
| fi | |
| - name: Get Changed Asset Files | |
| id: changed-assets | |
| uses: tj-actions/changed-files@v46 | |
| with: | |
| files: | | |
| data-assets/** | |
| json: true | |
| escape_json: false | |
| write_output_files: true | |
| - name: Rename Asset Output Files | |
| run: | | |
| if [ -f .github/outputs/all_changed_files.json ]; then | |
| mv .github/outputs/all_changed_files.json .github/outputs/assets_changed_files.json | |
| else | |
| echo "[]" > .github/outputs/assets_changed_files.json | |
| fi | |
| - name: Check if Sync is Required | |
| id: check-sync | |
| run: | | |
| echo "Checking if sync should run..." | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| if [[ "${{ contains(github.event.pull_request.labels.*.name, 'staging') }}" == "true" ]]; then | |
| echo "should_sync=true" >> $GITHUB_OUTPUT | |
| echo "β Sync enabled: PR has 'staging' label" | |
| else | |
| echo "should_sync=false" >> $GITHUB_OUTPUT | |
| echo "βοΈ Sync skipped: PR does not have 'staging' label" | |
| fi | |
| else | |
| echo "should_sync=true" >> $GITHUB_OUTPUT | |
| echo "β Sync enabled: Push event to branch" | |
| fi | |
| - name: Determine Deployment Status | |
| id: determine-status | |
| run: | | |
| if [[ "${{ github.event_name }}" == "pull_request" ]]; then | |
| if [[ "${{ contains(github.event.pull_request.labels.*.name, 'staging') }}" == "true" ]]; then | |
| echo "deployment_status=staging" >> $GITHUB_OUTPUT | |
| echo "π¦ Deployment Status: staging" | |
| else | |
| echo "deployment_status=draft" >> $GITHUB_OUTPUT | |
| echo "π¦ Deployment Status: draft" | |
| fi | |
| elif [[ "${{ github.ref }}" == "refs/heads/${{ env.PRODUCTION_BRANCH }}" ]]; then | |
| echo "deployment_status=live" >> $GITHUB_OUTPUT | |
| echo "π¦ Deployment Status: live" | |
| elif [[ "${{ github.ref }}" == "refs/heads/${{ env.STAGING_BRANCH }}" ]]; then | |
| echo "deployment_status=staging" >> $GITHUB_OUTPUT | |
| echo "π¦ Deployment Status: staging" | |
| else | |
| echo "deployment_status=draft" >> $GITHUB_OUTPUT | |
| echo "π¦ Deployment Status: draft" | |
| fi | |
| - name: Upload Changed Files Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: changed-files-json | |
| path: .github/outputs/*.json | |
| retention-days: 1 | |
| - name: Display Changed Files Summary | |
| if: steps.changed-content.outputs.any_changed == 'true' | |
| run: | | |
| echo "π Changed content files detected." | |
| echo "Count: $(jq '. | length' .github/outputs/content_changed_files.json)" | |
| - name: Display Deleted Files Summary | |
| if: steps.changed-content.outputs.any_deleted == 'true' | |
| run: | | |
| echo "ποΈ Deleted content files detected." | |
| echo "Count: $(jq '. | length' .github/outputs/content_deleted_files.json)" | |
| - name: Display Changed Assets Summary | |
| if: steps.changed-assets.outputs.any_changed == 'true' | |
| run: | | |
| echo "πΌοΈ Changed assets detected." | |
| echo "Count: $(jq '. | length' .github/outputs/assets_changed_files.json)" | |
| sync-to-cms: | |
| name: Sync Content to CMS | |
| runs-on: ubuntu-latest | |
| needs: detect-changes | |
| if: (needs.detect-changes.outputs.any_changed == 'true' || needs.detect-changes.outputs.any_deleted == 'true' || needs.detect-changes.outputs.any_assets_changed == 'true') && needs.detect-changes.outputs.should_sync == 'true' | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 2 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Download Changed Files Artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: changed-files-json | |
| path: .github/outputs | |
| - name: Install Dependencies | |
| run: | | |
| npm install --no-save \ | |
| gray-matter \ | |
| axios \ | |
| js-yaml \ | |
| mime-types \ | |
| @aws-sdk/client-s3 | |
| - name: Set Environment Specific Variables | |
| id: set-env-vars | |
| env: | |
| DEPLOYMENT_STATUS: ${{ needs.detect-changes.outputs.deployment_status }} | |
| # Production Secrets | |
| PROD_S3_BUCKET: ${{ secrets.S3_BUCKET_NAME }} | |
| PROD_CDN_URL: ${{ secrets.CDN_URL }} | |
| PROD_AWS_KEY: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| PROD_AWS_SECRET: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| STAGING_S3_BUCKET: ${{ secrets.S3_BUCKET_NAME_STAGING || secrets.S3_BUCKET_NAME }} | |
| STAGING_CDN_URL: ${{ secrets.CDN_URL_STAGING || secrets.CDN_URL }} | |
| STAGING_AWS_KEY: ${{ secrets.AWS_ACCESS_KEY_ID_STAGING || secrets.AWS_ACCESS_KEY_ID }} | |
| STAGING_AWS_SECRET: ${{ secrets.AWS_SECRET_ACCESS_KEY_STAGING || secrets.AWS_SECRET_ACCESS_KEY }} | |
| run: | | |
| echo "Configuring environment for status: $DEPLOYMENT_STATUS" | |
| if [[ "$DEPLOYMENT_STATUS" == "staging" ]]; then | |
| echo "S3_BUCKET_NAME=$STAGING_S3_BUCKET" >> $GITHUB_ENV | |
| echo "CDN_URL=$STAGING_CDN_URL" >> $GITHUB_ENV | |
| echo "AWS_ACCESS_KEY_ID=$STAGING_AWS_KEY" >> $GITHUB_ENV | |
| echo "AWS_SECRET_ACCESS_KEY=$STAGING_AWS_SECRET" >> $GITHUB_ENV | |
| echo "β Using Staging S3 Configuration" | |
| else | |
| echo "S3_BUCKET_NAME=$PROD_S3_BUCKET" >> $GITHUB_ENV | |
| echo "CDN_URL=$PROD_CDN_URL" >> $GITHUB_ENV | |
| echo "AWS_ACCESS_KEY_ID=$PROD_AWS_KEY" >> $GITHUB_ENV | |
| echo "AWS_SECRET_ACCESS_KEY=$PROD_AWS_SECRET" >> $GITHUB_ENV | |
| echo "β Using Production S3 Configuration" | |
| fi | |
| - name: Sync Content to Strapi | |
| id: sync | |
| env: | |
| CHANGED_FILES_PATH: .github/outputs/content_changed_files.json | |
| DELETED_FILES_PATH: .github/outputs/content_deleted_files.json | |
| CHANGED_ASSETS_PATH: .github/outputs/assets_changed_files.json | |
| DEPLOYMENT_STATUS: ${{ needs.detect-changes.outputs.deployment_status }} | |
| run: node scripts/sync-content-to-strapi.js | |
| - name: Trigger Revalidation | |
| if: success() | |
| env: | |
| DEPLOYMENT_STATUS: ${{ needs.detect-changes.outputs.deployment_status }} | |
| run: | | |
| echo "π Triggering ISR revalidation..." | |
| echo "Environment: $DEPLOYMENT_STATUS" | |
| # Determine the base URL based on deployment status | |
| if [ "$DEPLOYMENT_STATUS" = "live" ]; then | |
| BASE_URL="${{ env.NEXT_PUBLIC_BASE_URL }}" | |
| echo "Using production URL: $BASE_URL" | |
| elif [ "$DEPLOYMENT_STATUS" = "staging" ]; then | |
| BASE_URL="${{ env.NEXT_PUBLIC_STAGING_BASE_URL }}" | |
| echo "Using staging URL: $BASE_URL" | |
| else | |
| echo "βοΈ Skipping revalidation for draft deployment" | |
| exit 0 | |
| fi | |
| RESPONSE=$(curl -s -w "\n%{http_code}" --location "$BASE_URL/api/revalidate" \ | |
| --header 'Content-Type: application/json' \ | |
| --data "{ | |
| \"revalidateAll\": true, | |
| \"clearCache\": true, | |
| \"secret\": \"${{ env.REVALIDATE_SECRET }}\" | |
| }") | |
| HTTP_CODE=$(echo "$RESPONSE" | tail -n1) | |
| BODY=$(echo "$RESPONSE" | head -n-1) | |
| if [ "$HTTP_CODE" -eq 200 ]; then | |
| echo "β Revalidation successful!" | |
| echo "Response: $BODY" | |
| else | |
| echo "β Revalidation failed with HTTP $HTTP_CODE" | |
| echo "Response: $BODY" | |
| exit 1 | |
| fi | |
| - name: Update PR Comment | |
| if: always() && github.event_name == 'pull_request' | |
| uses: actions/github-script@v7 | |
| env: | |
| JOB_STATUS: ${{ job.status }} | |
| DEPLOYMENT_STATUS: ${{ needs.detect-changes.outputs.deployment_status }} | |
| with: | |
| script: | | |
| const script = require('${{ github.workspace }}/scripts/update-pr-comment.js'); | |
| await script({github, context, core}); | |
| report-status: | |
| name: Report Status | |
| runs-on: ubuntu-latest | |
| needs: [detect-changes, sync-to-cms] | |
| if: always() | |
| steps: | |
| - name: Report Success | |
| if: needs.sync-to-cms.result == 'success' | |
| run: | | |
| echo "β Workflow completed successfully!" | |
| echo "Deployment Status: ${{ needs.detect-changes.outputs.deployment_status }}" | |
| - name: Report Failure | |
| if: needs.sync-to-cms.result == 'failure' | |
| run: | | |
| echo "β Workflow failed!" | |
| echo "Please check the logs above for detailed error messages." | |
| exit 1 | |
| - name: Report Skipped | |
| if: needs.detect-changes.outputs.should_sync != 'true' || (needs.detect-changes.outputs.any_changed != 'true' && needs.detect-changes.outputs.any_deleted != 'true' && needs.detect-changes.outputs.any_assets_changed != 'true') | |
| run: | | |
| echo "βοΈ Sync was skipped." | |
| if [[ "${{ needs.detect-changes.outputs.any_changed }}" != "true" && "${{ needs.detect-changes.outputs.any_deleted }}" != "true" && "${{ needs.detect-changes.outputs.any_assets_changed }}" != "true" ]]; then | |
| echo "Reason: No content or asset files changed or deleted" | |
| else | |
| echo "Reason: PR does not have 'staging' label" | |
| fi |