From 9409a07a4d9e927b8ff10e36568c7a6ffd93936e Mon Sep 17 00:00:00 2001 From: netanelC Date: Tue, 8 Jul 2025 18:37:02 +0300 Subject: [PATCH 1/4] feat: add branch support --- .github/workflows/test-update-artifacts-file.yml | 1 + actions/update-artifacts-file/README.md | 1 + actions/update-artifacts-file/action.yaml | 7 +++++++ actions/update-artifacts-file/commit_changes.sh | 6 ++++-- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-update-artifacts-file.yml b/.github/workflows/test-update-artifacts-file.yml index 5c2fd2e..5110010 100644 --- a/.github/workflows/test-update-artifacts-file.yml +++ b/.github/workflows/test-update-artifacts-file.yml @@ -23,3 +23,4 @@ jobs: artifact_tag: "5.0.17" registry: ${{ secrets.ACR_URL }} github_token: ${{ secrets.GH_PAT }} + target_repo: "mapcolonies/helm-charts-test" diff --git a/actions/update-artifacts-file/README.md b/actions/update-artifacts-file/README.md index beec798..9fe263f 100644 --- a/actions/update-artifacts-file/README.md +++ b/actions/update-artifacts-file/README.md @@ -23,6 +23,7 @@ This GitHub Action builds and publishes a Helm chart to a specified registry and | `registry` | Registry URL the artifact is pushed to (e.g., ACR address) | ✅ Yes | | | `github_token` | GitHub token with permission to clone, commit & push to the target repo | ✅ Yes | | | `target_repo` | Target GitHub repo where `artifacts.json` should be updated (e.g. `org/repo`)| ❌ No | `mapcolonies/helm-charts` | +| `target_branch` | Target branch in the repository to update | ❌ No | `master` | --- diff --git a/actions/update-artifacts-file/action.yaml b/actions/update-artifacts-file/action.yaml index 5f3bcb7..54df9e0 100644 --- a/actions/update-artifacts-file/action.yaml +++ b/actions/update-artifacts-file/action.yaml @@ -27,6 +27,10 @@ inputs: description: "Target GitHub repository" required: false default: "mapcolonies/helm-charts" + target_branch: + description: "Target branch in the repository to update" + required: false + default: "master" runs: using: "composite" @@ -37,6 +41,7 @@ runs: repository: ${{ inputs.target_repo }} token: ${{ inputs.github_token }} path: $TARGET_PATH + ref: ${{ inputs.target_branch }} - name: Set execute permission on modify script run: chmod +x actions/update-artifacts-file/modify_artifacts.sh @@ -52,6 +57,7 @@ runs: TYPE: ${{ inputs.type }} REGISTRY: ${{ inputs.registry }} TARGET_DIR: $TARGET_PATH + TARGET_BRANCH: ${{ inputs.target_branch }} - name: Set execute permission on commit script run: chmod +x actions/update-artifacts-file/commit_changes.sh @@ -68,6 +74,7 @@ runs: GITHUB_TOKEN: ${{ inputs.github_token }} TARGET_REPO: ${{ inputs.target_repo }} TARGET_DIR: $TARGET_PATH + TARGET_BRANCH: ${{ inputs.target_branch }} - name: Clean up target repo folder run: rm -rf $TARGET_PATH diff --git a/actions/update-artifacts-file/commit_changes.sh b/actions/update-artifacts-file/commit_changes.sh index ae89ae6..8316862 100644 --- a/actions/update-artifacts-file/commit_changes.sh +++ b/actions/update-artifacts-file/commit_changes.sh @@ -4,19 +4,21 @@ cd "$TARGET_DIR" git config user.name "mapcolonies[bot]" git config user.email "devops[bot]@mapcolonies.com" +git checkout "$TARGET_BRANCH" + git add "$DOMAIN/artifacts.json" git commit -m "chore: update artifacts.json for $DOMAIN" -m "with $TYPE artifact: $ARTIFACT_NAME:$ARTIFACT_TAG" || echo "Nothing to commit" success=false for ((i=1; i<=5; i++)); do echo "Attempt $i to push changes..." - if git push https://x-access-token:$GITHUB_TOKEN@github.com/$TARGET_REPO.git; then + if git push https://x-access-token:$GITHUB_TOKEN@github.com/$TARGET_REPO.git "$TARGET_BRANCH"; then success=true echo "Push succeeded" break else echo "Push failed, retrying after pull" - git pull origin master --ff-only || true + git pull origin "$TARGET_BRANCH" --ff-only || true sleep 5 fi done From 8b34bbd6964001ce27fef4c9f51611649257bdbb Mon Sep 17 00:00:00 2001 From: netanelC Date: Tue, 8 Jul 2025 18:47:01 +0300 Subject: [PATCH 2/4] build: run PR on the path --- .github/workflows/test-artifactory-login.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/test-artifactory-login.yaml b/.github/workflows/test-artifactory-login.yaml index dc95594..977c6c5 100644 --- a/.github/workflows/test-artifactory-login.yaml +++ b/.github/workflows/test-artifactory-login.yaml @@ -1,9 +1,7 @@ name: Test artifactory-login action on: - push: - branches: - - master + pull_request: paths: - "actions/artifactory-login/**" From 727fec464edfb6205ae5957d525aaec55488725e Mon Sep 17 00:00:00 2001 From: netanelC Date: Tue, 8 Jul 2025 18:50:42 +0300 Subject: [PATCH 3/4] ci: fix pull requests checks --- .github/workflows/test-build-and-push-docker.yaml | 4 +--- .github/workflows/test-build-and-push-helm.yaml | 4 +--- .github/workflows/test-eslint.yml | 3 --- .github/workflows/test-helm-lint.yml | 5 ++--- .github/workflows/test-init-npm.yaml | 3 --- .github/workflows/test-openapi-lint.yaml | 3 --- .github/workflows/test-update-artifacts-file.yml | 4 +--- 7 files changed, 5 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test-build-and-push-docker.yaml b/.github/workflows/test-build-and-push-docker.yaml index 3dd3f62..8a87059 100644 --- a/.github/workflows/test-build-and-push-docker.yaml +++ b/.github/workflows/test-build-and-push-docker.yaml @@ -1,9 +1,7 @@ name: Test Build and Push Docker Image on: - push: - branches: - - master + pull_request: paths: - "actions/build-docker/**" - "actions/push-docker/**" diff --git a/.github/workflows/test-build-and-push-helm.yaml b/.github/workflows/test-build-and-push-helm.yaml index 05f1c82..8a57b4e 100644 --- a/.github/workflows/test-build-and-push-helm.yaml +++ b/.github/workflows/test-build-and-push-helm.yaml @@ -1,9 +1,7 @@ name: Test Build and Push Helm Chart on: - push: - branches: - - master + pull_request: paths: - "actions/build-and-push-helm/**" diff --git a/.github/workflows/test-eslint.yml b/.github/workflows/test-eslint.yml index 8acd577..e520887 100644 --- a/.github/workflows/test-eslint.yml +++ b/.github/workflows/test-eslint.yml @@ -2,9 +2,6 @@ name: Test ESLint repository on: pull_request: - push: - branches: - - master paths: - "actions/eslint/**" diff --git a/.github/workflows/test-helm-lint.yml b/.github/workflows/test-helm-lint.yml index bc8531e..ada31ff 100644 --- a/.github/workflows/test-helm-lint.yml +++ b/.github/workflows/test-helm-lint.yml @@ -1,9 +1,7 @@ name: Helm Lint repository on: - push: - branches: - - master + pull_request: paths: - "actions/helm-lint/**" @@ -20,6 +18,7 @@ jobs: - name: helm lint uses: ./actions/helm-lint + id: helm-lint with: repository: ${{ github.repository }} chartDirs: "./test/helm" diff --git a/.github/workflows/test-init-npm.yaml b/.github/workflows/test-init-npm.yaml index 1bb9d0c..cf7fac2 100644 --- a/.github/workflows/test-init-npm.yaml +++ b/.github/workflows/test-init-npm.yaml @@ -2,9 +2,6 @@ name: Init-npm repository on: pull_request: - push: - branches: - - master paths: - "actions/init-npm/**" diff --git a/.github/workflows/test-openapi-lint.yaml b/.github/workflows/test-openapi-lint.yaml index bc6873b..142628a 100644 --- a/.github/workflows/test-openapi-lint.yaml +++ b/.github/workflows/test-openapi-lint.yaml @@ -2,9 +2,6 @@ name: Test OpenApi-lint on: pull_request: - push: - branches: - - master paths: - "actions/opanapi-lint/**" diff --git a/.github/workflows/test-update-artifacts-file.yml b/.github/workflows/test-update-artifacts-file.yml index 5110010..c0aa978 100644 --- a/.github/workflows/test-update-artifacts-file.yml +++ b/.github/workflows/test-update-artifacts-file.yml @@ -1,9 +1,7 @@ name: Update artifacts.json on: - push: - branches: - - master + pull_request: paths: - "actions/update-artifacts-file/**" From 1313cb52570996b13dacaad8c8033ab115a48899 Mon Sep 17 00:00:00 2001 From: netanelC Date: Tue, 8 Jul 2025 19:04:35 +0300 Subject: [PATCH 4/4] chore: remove unnecessary change --- actions/update-artifacts-file/action.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/actions/update-artifacts-file/action.yaml b/actions/update-artifacts-file/action.yaml index 54df9e0..6f2363b 100644 --- a/actions/update-artifacts-file/action.yaml +++ b/actions/update-artifacts-file/action.yaml @@ -57,7 +57,6 @@ runs: TYPE: ${{ inputs.type }} REGISTRY: ${{ inputs.registry }} TARGET_DIR: $TARGET_PATH - TARGET_BRANCH: ${{ inputs.target_branch }} - name: Set execute permission on commit script run: chmod +x actions/update-artifacts-file/commit_changes.sh