From f2219b012649b768cd8038fde3d086b3351c79f0 Mon Sep 17 00:00:00 2001 From: Dilip Kola Date: Mon, 9 Dec 2024 20:34:54 +0530 Subject: [PATCH 1/3] chore: add gh workflow for raising pr for constants --- .github/workflows/check-generated.yml | 2 + .github/workflows/raise-pr-for-constants.yml | 72 ++++++++++++++++++++ generated/Destinations.dart | 4 +- generated/Destinations.java | 4 +- generated/Destinations.kt | 4 +- generated/Destinations.m | 4 +- generated/Destinations.swift | 4 +- generated/Destinations.ts | 4 +- templates/Destinations.dart.template | 4 +- templates/Destinations.java.template | 4 +- templates/Destinations.kt.template | 4 +- templates/Destinations.m.template | 4 +- templates/Destinations.swift.template | 4 +- templates/Destinations.ts.template | 4 +- 14 files changed, 98 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/raise-pr-for-constants.yml diff --git a/.github/workflows/check-generated.yml b/.github/workflows/check-generated.yml index b6d021c80..fbba03691 100644 --- a/.github/workflows/check-generated.yml +++ b/.github/workflows/check-generated.yml @@ -32,6 +32,8 @@ jobs: run: | if [ -n "$(git status --porcelain)" ]; then echo "::error::Generated constants are not up-to-date. Run 'npm run generate:constants' and commit the changes."; + echo "Here are the differences:"; + git diff; exit 1; else echo "Git state is clean."; diff --git a/.github/workflows/raise-pr-for-constants.yml b/.github/workflows/raise-pr-for-constants.yml new file mode 100644 index 000000000..b17cfed17 --- /dev/null +++ b/.github/workflows/raise-pr-for-constants.yml @@ -0,0 +1,72 @@ +name: Raise PR for Destination Constants + +on: + push: + branches: + - develop + +permissions: + contents: write + pull-requests: write + +env: + BRANCH_NAME: chore/gh-update-destinations-ts + +jobs: + check_changes: + runs-on: ubuntu-latest + outputs: + pr_required: ${{ steps.compare_files.outputs.pr_required }} + steps: + - name: Checkout Source Repo + uses: actions/checkout@v4 + with: + ref: develop + + - name: Checkout Destination Repo + run: | + DEST_REPO="rudderlabs/rudder-sdk-js" + git clone https://github.com/${DEST_REPO}.git dest-repo + cd dest-repo + git config --global user.name "GitHub Actions" + git config --global user.email "noreply@github.com" + git config --global url."https://${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/" + git checkout -b ${{ env.BRANCH_NAME }} + git pull origin ${{ env.BRANCH_NAME }} || echo "No updates to pull" + + - name: Compare Destinations.ts + id: compare_files + run: | + SRC_FILE="generated/Destinations.ts" + DEST_REPO="rudderlabs/rudder-sdk-js" + DEST_PATH="packages/analytics-js-common/src/constants/integrations/Destinations.ts" + + if cmp -s "$SRC_FILE" "dest-repo/$DEST_PATH"; then + echo "No changes detected." > result.txt + echo "pr_required=false" >> $GITHUB_OUTPUT + else + echo "Changes detected." > result.txt + echo "pr_required=true" >> $GITHUB_OUTPUT + fi + raise_pr: + needs: check_changes + if: needs.check_changes.outputs.pr_required == 'true' + runs-on: ubuntu-latest + steps: + - name: Commit and Push Changes + run: | + cd dest-repo + cp "../generated/Destinations.ts" "packages/analytics-js-common/src/constants/integrations/Destinations.ts" + git add packages/analytics-js-common/src/constants/integrations/Destinations.ts + git commit -m "chore: update destinations.ts" + git push origin ${{ env.BRANCH_NAME }} + + - name: Create or Update PR + run: | + cd dest-repo + EXISTING_PR=$(gh pr list --head ${{ env.BRANCH_NAME }} --json number --jq ".[0].number") + if [ -z "$EXISTING_PR" ]; then + gh pr create -f + else + echo "PR already exists: $EXISTING_PR" + fi diff --git a/generated/Destinations.dart b/generated/Destinations.dart index 9c2159fb5..be0ef7a06 100644 --- a/generated/Destinations.dart +++ b/generated/Destinations.dart @@ -1,9 +1,9 @@ /* GENERATED - DO NOT EDIT This file is generated from the templates/Destinations.dart.template file. - Orginal file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.dart + Original file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.dart - NOTE: Containly only constants for device mode destinations + NOTE: Contains only constants for device mode destinations */ class Destinations { diff --git a/generated/Destinations.java b/generated/Destinations.java index b1d57fd79..092d09b2c 100644 --- a/generated/Destinations.java +++ b/generated/Destinations.java @@ -1,9 +1,9 @@ /* GENERATED - DO NOT EDIT This file is generated from the templates/Destinations.java.template file. - Orginal file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.java + Original file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.java - NOTE: Containly only constants for device mode destinations + NOTE: Contains only constants for device mode destinations */ public class Destinations { diff --git a/generated/Destinations.kt b/generated/Destinations.kt index d26980292..02178de38 100644 --- a/generated/Destinations.kt +++ b/generated/Destinations.kt @@ -1,9 +1,9 @@ /* GENERATED - DO NOT EDIT This file is generated from the templates/Destinations.kt.template file. - Orginal file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.kt + Original file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.kt - NOTE: Containly only constants for device mode destinations + NOTE: Contains only constants for device mode destinations */ object Destinations { diff --git a/generated/Destinations.m b/generated/Destinations.m index c0b98180b..1bf83b059 100644 --- a/generated/Destinations.m +++ b/generated/Destinations.m @@ -1,9 +1,9 @@ /* GENERATED - DO NOT EDIT This file is generated from the templates/Destinations.m.template file. - Orginal file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.m + Original file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.m - NOTE: Containly only constants for device mode destinations */ + NOTE: Contains only constants for device mode destinations */ #import diff --git a/generated/Destinations.swift b/generated/Destinations.swift index 368d890df..cd9694920 100644 --- a/generated/Destinations.swift +++ b/generated/Destinations.swift @@ -1,9 +1,9 @@ /* GENERATED - DO NOT EDIT This file is generated from the templates/Destinations.swift.template file. - Orginal file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.swift + Original file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.swift - NOTE: Containly only constants for device mode destinations + NOTE: Contains only constants for device mode destinations */ struct Destinations { diff --git a/generated/Destinations.ts b/generated/Destinations.ts index e97f1016c..a764b822c 100644 --- a/generated/Destinations.ts +++ b/generated/Destinations.ts @@ -1,9 +1,9 @@ /* GENERATED - DO NOT EDIT This file is generated from the templates/Destinations.ts.template file. - Orginal file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.ts + Original file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.ts - NOTE: Containly only constants for device mode destinations + NOTE: Contains only constants for device mode destinations */ export const ACTIVE_CAMPAIGN_NAME = 'ACTIVE_CAMPAIGN'; export const ACTIVE_CAMPAIGN_DISPLAY_NAME = 'ActiveCampaign'; diff --git a/templates/Destinations.dart.template b/templates/Destinations.dart.template index f78f19489..9b6b5b615 100644 --- a/templates/Destinations.dart.template +++ b/templates/Destinations.dart.template @@ -1,9 +1,9 @@ /* GENERATED - DO NOT EDIT This file is generated from the templates/Destinations.dart.template file. - Orginal file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.dart + Original file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.dart - NOTE: Containly only constants for device mode destinations + NOTE: Contains only constants for device mode destinations */ class Destinations { diff --git a/templates/Destinations.java.template b/templates/Destinations.java.template index 941f2cebc..b1cb12bb0 100644 --- a/templates/Destinations.java.template +++ b/templates/Destinations.java.template @@ -1,9 +1,9 @@ /* GENERATED - DO NOT EDIT This file is generated from the templates/Destinations.java.template file. - Orginal file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.java + Original file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.java - NOTE: Containly only constants for device mode destinations + NOTE: Contains only constants for device mode destinations */ public class Destinations { diff --git a/templates/Destinations.kt.template b/templates/Destinations.kt.template index 66feb5340..c6ca2a5cb 100644 --- a/templates/Destinations.kt.template +++ b/templates/Destinations.kt.template @@ -1,9 +1,9 @@ /* GENERATED - DO NOT EDIT This file is generated from the templates/Destinations.kt.template file. - Orginal file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.kt + Original file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.kt - NOTE: Containly only constants for device mode destinations + NOTE: Contains only constants for device mode destinations */ object Destinations { diff --git a/templates/Destinations.m.template b/templates/Destinations.m.template index 3c091322e..0b53a7c8c 100644 --- a/templates/Destinations.m.template +++ b/templates/Destinations.m.template @@ -1,9 +1,9 @@ /* GENERATED - DO NOT EDIT This file is generated from the templates/Destinations.m.template file. - Orginal file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.m + Original file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.m - NOTE: Containly only constants for device mode destinations */ + NOTE: Contains only constants for device mode destinations */ #import diff --git a/templates/Destinations.swift.template b/templates/Destinations.swift.template index 735c26006..a0af3a6e6 100644 --- a/templates/Destinations.swift.template +++ b/templates/Destinations.swift.template @@ -1,9 +1,9 @@ /* GENERATED - DO NOT EDIT This file is generated from the templates/Destinations.swift.template file. - Orginal file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.swift + Original file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.swift - NOTE: Containly only constants for device mode destinations + NOTE: Contains only constants for device mode destinations */ struct Destinations { diff --git a/templates/Destinations.ts.template b/templates/Destinations.ts.template index 30b567063..582562b0e 100644 --- a/templates/Destinations.ts.template +++ b/templates/Destinations.ts.template @@ -1,9 +1,9 @@ /* GENERATED - DO NOT EDIT This file is generated from the templates/Destinations.ts.template file. - Orginal file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.ts + Original file: https://github.com/rudderlabs/rudder-integrations-config/blob/develop/generated/Destinations.ts - NOTE: Containly only constants for device mode destinations + NOTE: Contains only constants for device mode destinations */ ${ destinations.map((dest) => From 993b522367c54b4975142e0967ff1472960dd621 Mon Sep 17 00:00:00 2001 From: Dilip Kola Date: Tue, 10 Dec 2024 09:42:57 +0530 Subject: [PATCH 2/3] fix: pr comments --- .github/workflows/check-generated.yml | 2 +- .github/workflows/raise-pr-for-constants.yml | 31 +++++++++++++------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/.github/workflows/check-generated.yml b/.github/workflows/check-generated.yml index fbba03691..d8c40f7ac 100644 --- a/.github/workflows/check-generated.yml +++ b/.github/workflows/check-generated.yml @@ -33,7 +33,7 @@ jobs: if [ -n "$(git status --porcelain)" ]; then echo "::error::Generated constants are not up-to-date. Run 'npm run generate:constants' and commit the changes."; echo "Here are the differences:"; - git diff; + git diff || true 2>&1; exit 1; else echo "Git state is clean."; diff --git a/.github/workflows/raise-pr-for-constants.yml b/.github/workflows/raise-pr-for-constants.yml index b17cfed17..f088ca122 100644 --- a/.github/workflows/raise-pr-for-constants.yml +++ b/.github/workflows/raise-pr-for-constants.yml @@ -11,6 +11,8 @@ permissions: env: BRANCH_NAME: chore/gh-update-destinations-ts + SRC_FILE: generated/Destinations.ts + DEST_PATH: packages/analytics-js-common/src/constants/integrations/Destinations.ts jobs: check_changes: @@ -26,28 +28,25 @@ jobs: - name: Checkout Destination Repo run: | DEST_REPO="rudderlabs/rudder-sdk-js" - git clone https://github.com/${DEST_REPO}.git dest-repo + git clone https://github.com/${DEST_REPO}.git dest-repo || exit 1 cd dest-repo git config --global user.name "GitHub Actions" git config --global user.email "noreply@github.com" git config --global url."https://${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/" git checkout -b ${{ env.BRANCH_NAME }} - git pull origin ${{ env.BRANCH_NAME }} || echo "No updates to pull" - + git pull origin ${{ env.BRANCH_NAME }} || true + - name: Compare Destinations.ts id: compare_files run: | - SRC_FILE="generated/Destinations.ts" - DEST_REPO="rudderlabs/rudder-sdk-js" - DEST_PATH="packages/analytics-js-common/src/constants/integrations/Destinations.ts" - - if cmp -s "$SRC_FILE" "dest-repo/$DEST_PATH"; then - echo "No changes detected." > result.txt + if cmp -s "${{ env.SRC_FILE }}" "dest-repo/${{ env.DEST_PATH }}"; then + echo "No changes detected." > "result.txt" echo "pr_required=false" >> $GITHUB_OUTPUT else - echo "Changes detected." > result.txt + echo "Changes detected." > "result.txt" echo "pr_required=true" >> $GITHUB_OUTPUT fi + raise_pr: needs: check_changes if: needs.check_changes.outputs.pr_required == 'true' @@ -62,11 +61,21 @@ jobs: git push origin ${{ env.BRANCH_NAME }} - name: Create or Update PR + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | cd dest-repo EXISTING_PR=$(gh pr list --head ${{ env.BRANCH_NAME }} --json number --jq ".[0].number") if [ -z "$EXISTING_PR" ]; then - gh pr create -f + gh pr create \ + --title "chore: update destination constants" \ + --body "This PR updates the destination constants file. + + **Changes:** + - Updated \`Destinations.ts\` with latest constants + + This PR was automatically generated by GitHub Actions." \ + --label "automated,dependencies" else echo "PR already exists: $EXISTING_PR" fi From a5331eec00ca9a4cf0eef1ce3b2a20f97619bebf Mon Sep 17 00:00:00 2001 From: Dilip Kola Date: Tue, 10 Dec 2024 11:09:27 +0530 Subject: [PATCH 3/3] fix: pr comments --- .github/workflows/raise-pr-for-constants.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/raise-pr-for-constants.yml b/.github/workflows/raise-pr-for-constants.yml index f088ca122..c509f166a 100644 --- a/.github/workflows/raise-pr-for-constants.yml +++ b/.github/workflows/raise-pr-for-constants.yml @@ -10,7 +10,7 @@ permissions: pull-requests: write env: - BRANCH_NAME: chore/gh-update-destinations-ts + BRANCH_NAME: fix/gh-update-destinations-ts SRC_FILE: generated/Destinations.ts DEST_PATH: packages/analytics-js-common/src/constants/integrations/Destinations.ts @@ -33,8 +33,7 @@ jobs: git config --global user.name "GitHub Actions" git config --global user.email "noreply@github.com" git config --global url."https://${{ secrets.GITHUB_TOKEN }}@github.com/".insteadOf "https://github.com/" - git checkout -b ${{ env.BRANCH_NAME }} - git pull origin ${{ env.BRANCH_NAME }} || true + git checkout ${{ env.BRANCH_NAME }} || git checkout -b ${{ env.BRANCH_NAME }} - name: Compare Destinations.ts id: compare_files @@ -57,7 +56,7 @@ jobs: cd dest-repo cp "../generated/Destinations.ts" "packages/analytics-js-common/src/constants/integrations/Destinations.ts" git add packages/analytics-js-common/src/constants/integrations/Destinations.ts - git commit -m "chore: update destinations.ts" + git commit -m "fix: update destinations.ts" git push origin ${{ env.BRANCH_NAME }} - name: Create or Update PR @@ -68,7 +67,7 @@ jobs: EXISTING_PR=$(gh pr list --head ${{ env.BRANCH_NAME }} --json number --jq ".[0].number") if [ -z "$EXISTING_PR" ]; then gh pr create \ - --title "chore: update destination constants" \ + --title "fix: update destination constants" \ --body "This PR updates the destination constants file. **Changes:**