From 7678caf1b25f1ef80b60b9ffcb17165ec1bda8de Mon Sep 17 00:00:00 2001 From: Francesco Medas Date: Wed, 29 Mar 2023 15:28:16 +0400 Subject: [PATCH 1/2] feat: enable push only if a PR to master is open and avoid multiple run per commit --- .github/workflows/ci-image-dev.yml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-image-dev.yml b/.github/workflows/ci-image-dev.yml index 46df1b8f82..57fbaa4e54 100644 --- a/.github/workflows/ci-image-dev.yml +++ b/.github/workflows/ci-image-dev.yml @@ -10,9 +10,6 @@ on: push: branches-ignore: - 'release/**' - pull_request: - branches: - - 'master' jobs: push-to-ecr: @@ -29,11 +26,24 @@ jobs: docker system df docker system prune -a -f --filter "until=336h" docker system df - - name: 'Checkout scm ${{ inputs.commitOrTag }}' + - name: 'Checkout scm' uses: actions/checkout@v3 with: fetch-depth: 0 ref: ${{ inputs.commitOrTag }} + - name: Check Pull Request open to the default branch + id: is-pr-open + run: | + pull_requests=$(curl -s -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/Zilliqa/Zilliqa/pulls?state=open&per_page=100&base=${{ github.event.repository.default_branch }}&head=${{ github.event.repository.owner.login }}:${{ github.ref_name }}" | jq -r ".[].url") + + if [ -n "$pull_requests" ]; then + echo "There is an open pull request from the current feature branch to the default branch" + echo "result=true" >> $GITHUB_OUTPUT + else + echo "There is no open pull request from the current feature branch to the default branch" + echo "result=false" >> $GITHUB_OUTPUT + fi + shell: bash - name: Configure AWS Credentials uses: Zilliqa/gh-actions-workflows/actions/configure-aws-credentials@v1 with: @@ -52,6 +62,6 @@ jobs: run: DOCKER_BUILDKIT=1 docker build -t ${{ secrets.AWS_ACCOUNT_ID_ZILLIQA }}.dkr.ecr.${{ secrets.AWS_REGION_ZILLIQA }}.amazonaws.com/zilliqa:${{ steps.set-tag.outputs.tag }} -f docker/Dockerfile . shell: bash - name: Push Docker images - if: github.event_name == 'pull_request' || github.ref_name == 'master' + if: steps.is-pr-open.outputs.result == 'true' || github.ref_name == 'master' run: docker push ${{ secrets.AWS_ACCOUNT_ID_ZILLIQA }}.dkr.ecr.${{ secrets.AWS_REGION_ZILLIQA }}.amazonaws.com/zilliqa:${{ steps.set-tag.outputs.tag }} - shell: bash \ No newline at end of file + shell: bash From c5ae2f69e634f39597a402791c9233223339b141 Mon Sep 17 00:00:00 2001 From: Francesco Medas Date: Wed, 29 Mar 2023 15:30:26 +0400 Subject: [PATCH 2/2] fix --- .github/workflows/ci-image-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-image-dev.yml b/.github/workflows/ci-image-dev.yml index 57fbaa4e54..753795919c 100644 --- a/.github/workflows/ci-image-dev.yml +++ b/.github/workflows/ci-image-dev.yml @@ -26,7 +26,7 @@ jobs: docker system df docker system prune -a -f --filter "until=336h" docker system df - - name: 'Checkout scm' + - name: 'Checkout scm ${{ inputs.commitOrTag }}' uses: actions/checkout@v3 with: fetch-depth: 0