From 5bbf9abe451bb1f81b624247dabe0c3c12458095 Mon Sep 17 00:00:00 2001 From: Denilson Nastacio Date: Tue, 8 Mar 2022 17:17:09 -0500 Subject: [PATCH] chore: Avoid dependency on branch existence --- .github/workflows/close-pr.yml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/merge-pr.yml | 9 +--- .github/workflows/test-pr.yml | 71 +++++++++++++++++--------------- tests/postbuild/calc-settings.sh | 20 +++++---- 5 files changed, 54 insertions(+), 50 deletions(-) diff --git a/.github/workflows/close-pr.yml b/.github/workflows/close-pr.yml index bf775145..eeb390f4 100644 --- a/.github/workflows/close-pr.yml +++ b/.github/workflows/close-pr.yml @@ -21,7 +21,7 @@ jobs: environment: dev steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Verify destroy run: tests/postbuild/cluster.sh --delete -t ibmcloud -n "gitops-${GITHUB_HEAD_REF}" --apikey "${IBM_CLOUD_API_KEY}" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 8b8bed8b..5fc90c71 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -13,7 +13,7 @@ jobs: # Steps represent a sequence of tasks that will be executed as part of the job steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 # Runs a single command using the runners shell - name: Run a one-line script diff --git a/.github/workflows/merge-pr.yml b/.github/workflows/merge-pr.yml index fa7da131..88ba5d58 100644 --- a/.github/workflows/merge-pr.yml +++ b/.github/workflows/merge-pr.yml @@ -15,18 +15,13 @@ jobs: env: PIPELINE_DEBUG: 1 - environment: dev - - outputs: - delta: ${{ steps.calc.outputs.delta }} - steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - id: calc if: github.event.pull_request.merged name: Determine extent of testing - run: tests/postbuild/calc-settings.sh "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" "${GITHUB_HEAD_REF}" "${GITHUB_BASE_REF}" + run: tests/postbuild/calc-settings.sh "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" "${GITHUB_SHA}" "${GITHUB_BASE_REF}" - name: Promote release if test passes if: github.event.pull_request.merged diff --git a/.github/workflows/test-pr.yml b/.github/workflows/test-pr.yml index 62839af5..9e626d75 100644 --- a/.github/workflows/test-pr.yml +++ b/.github/workflows/test-pr.yml @@ -5,57 +5,62 @@ on: branches: [main] jobs: - test: - if: ${{ !contains( github.event.pull_request.labels.*.name, 'skip ci' ) }} + calc: runs-on: ubuntu-latest - container: icr.io/continuous-delivery/pipeline/pipeline-base-ubi:3.6 env: HOME: /root PIPELINE_DEBUG: 1 - CP_ICR_IO_REPO: ${{ secrets.CP_ICR_IO_REPO }} - CP_ICR_IO_USERID: cp - CP_ICR_IO_PASSWORD: ${{ secrets.CP_ICR_IO_PASSWORD }} - IBM_CLOUD_API_KEY: ${{ secrets.IBM_CLOUD_API_KEY }} - - environment: dev - - outputs: - delta: ${{ steps.calc.outputs.delta }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - id: calc - name: Determine extent of testing - run: tests/postbuild/calc-settings.sh "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" "${GITHUB_HEAD_REF}" "${GITHUB_BASE_REF}" - - - name: Ensures target cluster exists - run: tests/postbuild/cluster.sh --ensure --wait -t ibmcloud -n "gitops-${GITHUB_HEAD_REF}" --apikey "${IBM_CLOUD_API_KEY}" --workers "$(cat test-sh-workers.txt)" --worker-flavor "c3c.32x64" --global-pull-secret "$(cat test-sh-gps.txt)" + - name: Determine extent of testing + run: tests/postbuild/calc-settings.sh "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" "${GITHUB_SHA}" "${GITHUB_BASE_REF}" - - name: Deploy Argo to the cluster - run: tests/postbuild/gitops.sh --setup-server -t ibmcloud -n "gitops-${GITHUB_HEAD_REF}" --gitops-repo "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" --gitops-branch "${GITHUB_HEAD_REF}" --apikey "${IBM_CLOUD_API_KEY}" --application-labels "$(cat test-sh-labels.txt)" + - name: Upload global pull secret result + uses: actions/upload-artifact@v1 + with: + name: calc + path: test-sh-gps.txt - name: Upload semver result uses: actions/upload-artifact@v1 with: - name: semver - path: test-sh-semver.txt + name: calc + path: test-sh-labels.txt - promote: + - name: Upload workers result + uses: actions/upload-artifact@v1 + with: + name: calc + path: test-sh-workers.txt + + test: if: ${{ !contains( github.event.pull_request.labels.*.name, 'skip ci' ) }} runs-on: ubuntu-latest - needs: test + container: icr.io/continuous-delivery/pipeline/pipeline-base-ubi:3.6 + + env: + HOME: /root + PIPELINE_DEBUG: 1 + CP_ICR_IO_REPO: ${{ secrets.CP_ICR_IO_REPO }} + CP_ICR_IO_USERID: cp + CP_ICR_IO_PASSWORD: ${{ secrets.CP_ICR_IO_PASSWORD }} + IBM_CLOUD_API_KEY: ${{ secrets.IBM_CLOUD_API_KEY }} + + environment: dev steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - name: Download semver result - uses: actions/download-artifact@v1 + - name: Download all workflow run artifacts + uses: actions/download-artifact@v3 with: - name: semver + name: calc + + - name: Ensures target cluster exists + run: tests/postbuild/cluster.sh --ensure --wait -t ibmcloud -n "gitops-${GITHUB_HEAD_REF}" --apikey "${IBM_CLOUD_API_KEY}" --workers "$(cat calc/test-sh-workers.txt)" --worker-flavor "c3c.32x64" --global-pull-secret "$(cat calc/test-sh-gps.txt)" - - name: Promote release if test passes - run: tests/postbuild/promote-release.sh "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" "${GITHUB_HEAD_REF}" "$(cat semver/test-sh-semver.txt)" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Deploy Argo and Cloud Paks to the cluster + run: tests/postbuild/gitops.sh --setup-server -t ibmcloud -n "gitops-${GITHUB_HEAD_REF}" --gitops-repo "${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}" --gitops-branch "${GITHUB_HEAD_REF}" --apikey "${IBM_CLOUD_API_KEY}" --application-labels "$(cat calc/test-sh-labels.txt)" diff --git a/tests/postbuild/calc-settings.sh b/tests/postbuild/calc-settings.sh index 0c3cbca2..0166b990 100755 --- a/tests/postbuild/calc-settings.sh +++ b/tests/postbuild/calc-settings.sh @@ -50,18 +50,22 @@ trap cleanRun EXIT function extract_branch_delta() { local output_file=${1} - local result=1 + local result=0 # # Analyze the differences between branches # to determine which Cloud Paks to test - git clone "${git_repo}" cloudpak-gitops - cd cloudpak-gitops - git config pull.rebase false - git checkout "${git_source_branch}" - git pull origin "${git_source_branch}" - git diff "${git_target_branch}" --name-only | tee "${output_file}" \ - && result=0 + git clone "${git_repo}" cloudpak-gitops \ + && cd cloudpak-gitops \ + && git config pull.rebase false \ + result=1 + + if [ ${result} -eq 0 ]; then + git pull origin "${git_source_branch}" || result=1 + git diff "${git_target_branch}" --name-only | tee "${output_file}" \ + && result=0 \ + || result=1 + fi return ${result} }