From 1c7ed1c69eef3f939e26b0b0d7471fe6dccbe2d7 Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Fri, 16 Feb 2024 18:40:02 +0800 Subject: [PATCH] [FEQ] Ako/ Create PR on Remote Config file change (#13627) * ci: create pr on remote config file update * ci: remove the PR step from action * ci: add EOF * ci: update the job name --- .../download_remote_config_backup/action.yml | 43 -------------- .github/workflows/remote_config_pr.yml | 59 +++++++++++++++++++ 2 files changed, 59 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/remote_config_pr.yml diff --git a/.github/actions/download_remote_config_backup/action.yml b/.github/actions/download_remote_config_backup/action.yml index 15b84e7277ba..1d4efadb3794 100644 --- a/.github/actions/download_remote_config_backup/action.yml +++ b/.github/actions/download_remote_config_backup/action.yml @@ -18,46 +18,3 @@ runs: curl ${{ inputs.REMOTE_CONFIG_URL }} > packages/api/src/remote_config.json echo "Remote Config backup downloaded successfully!" shell: bash - # - name: Import GPG key - # if: github.ref == 'refs/heads/master' - # id: import-gpg - # uses: deriv-com/ghaction-import-gpg@v6 - # with: - # gpg_private_key: ${{ inputs.GPG_PRIVATE_KEY }} - # passphrase: ${{ inputs.GPG_PASSPHRASE }} - # git_user_signingkey: true - # git_commit_gpgsign: true - # - name: commit changes - # if: github.ref == 'refs/heads/master' - # env: - # GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} - # GIT_AUTHOR_NAME: ${{ steps.import-gpg.outputs.name }} - # GIT_AUTHOR_EMAIL: ${{ steps.import-gpg.outputs.email }} - # GIT_COMMITTER_NAME: ${{ steps.import-gpg.outputs.name }} - # GIT_COMMITTER_EMAIL: ${{ steps.import-gpg.outputs.email }} - # run: | - # branch_name="remote_config_update_branch" - - # if [ -z "$(git status --porcelain)" ]; then - # echo "No changes to commit, Not creating a PR." - # else - # echo "Changes detected, creating a PR" - - # # Checkout to remote config branch - # git fetch origin - # git checkout "$branch_name" || git checkout -b "$branch_name" origin/"$branch_name" - - # # Commit the newly downloaded file - # cd $(git rev-parse --show-toplevel) - # git add packages/api/src/remote_config.json - # git commit -m "🤖 Remote Config file update 🤖" - - # # Force push to this branch in case a previous run created it. - # git push --set-upstream origin "$branch_name" -f - - # sudo apt install gh - # gh auth login --with-token <<< ${{ env.GITHUB_TOKEN }} - # gh pr close "$branch_name" || true - # gh pr create --base "master" --title "Sync Remote Config File 🤖" --head "binary-com:$branch_name" --body "This is an automated Pull Request designed to synchronize our project's Remote Config from Its origin. It checks for the changes in the remote config URL and in case of any change, it will update it using this PR." - # fi - # shell: bash diff --git a/.github/workflows/remote_config_pr.yml b/.github/workflows/remote_config_pr.yml new file mode 100644 index 000000000000..b0fe2e200695 --- /dev/null +++ b/.github/workflows/remote_config_pr.yml @@ -0,0 +1,59 @@ +name: Deriv App Remote Config backup file +on: + push: + branches: + - master + +jobs: + download_remote_config_backup_and_create_pr: + name: Download Remote Config Backup File and Create PR + runs-on: Runner_8cores_Deriv-app + env: + REMOTE_CONFIG_BRANCH: "remote_config_update_branch" + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: Checkout to remote_config_update_branch + run: | + git fetch origin + git checkout "${{ env.REMOTE_CONFIG_BRANCH }}" || git checkout -b "${{ env.REMOTE_CONFIG_BRANCH }}" origin/"${{ env.REMOTE_CONFIG_BRANCH }}" + + - name: Download Remote Config Backup File + uses: ./.github/actions/download_remote_config_backup + with: + REMOTE_CONFIG_URL: ${{ vars.REMOTE_CONFIG_URL }} + + - name: Import GPG key + id: import-gpg + uses: deriv-com/ghaction-import-gpg@v6 + with: + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} + passphrase: ${{ secrets.GPG_PASSPHRASE }} + git_user_signingkey: true + git_commit_gpgsign: true + - name: Commit the file and Create PR + env: + GIT_AUTHOR_NAME: ${{ steps.import-gpg.outputs.name }} + GIT_AUTHOR_EMAIL: ${{ steps.import-gpg.outputs.email }} + GIT_COMMITTER_NAME: ${{ steps.import-gpg.outputs.name }} + GIT_COMMITTER_EMAIL: ${{ steps.import-gpg.outputs.email }} + run: | + if [ -z "$(git status --porcelain)" ]; then + echo "No changes to commit, Not creating a PR." + else + echo "Changes detected, creating a PR" + + # Commit the newly downloaded file + cd $(git rev-parse --show-toplevel) + git add packages/api/src/remote_config.json + git commit -m "🤖 Remote Config file update 🤖" + + # Force push to this branch in case a previous run created it. + git push --set-upstream origin "${{ env.REMOTE_CONFIG_BRANCH }}" -f + + sudo apt install gh + gh auth login --with-token <<< ${{ github.token }} + gh pr close "${{ env.REMOTE_CONFIG_BRANCH }}" || true + gh pr create --base "master" --title "Sync Remote Config File 🤖" --head "binary-com:${{ env.REMOTE_CONFIG_BRANCH }}" --body "This is an automated Pull Request designed to synchronize our project's Remote Config from Its origin. It checks for the changes in the remote config URL and in case of any change, it will update it using this PR." + fi + shell: bash