Skip to content

Commit

Permalink
chore: Avoid dependency on branch existence
Browse files Browse the repository at this point in the history
  • Loading branch information
nastacio committed Mar 8, 2022
1 parent 97ea39d commit 5bbf9ab
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/close-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions .github/workflows/merge-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
71 changes: 38 additions & 33 deletions .github/workflows/test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
20 changes: 12 additions & 8 deletions tests/postbuild/calc-settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down

0 comments on commit 5bbf9ab

Please sign in to comment.