Skip to content

Commit

Permalink
add gh actions early success if change is docs only
Browse files Browse the repository at this point in the history
    Fixes GoogleContainerTools#6032, add code to not run Github Actions on docs-only changes. This PR:
    - Updates linux and osx github actions to check if the PR only changes docs/* files and if so, pass the test w/o running the full test suite

    Github actions does not have support for exiting the job from a step easily. See:
    - https://stackoverflow.com/questions/60589373/how-to-force-to-exit-in-github-actions-step
    - actions/runner#662
    The approach here uses an env var and checks this env var in all subsequent steps, this way no single command fails and tests are skipped as desired.  The downside is that all subsequent steps need to have this check but there is no better solution at the moment from my investigation

  I considered directly using the the 'conclusion' value github actions provides, eg:
  - "if: steps.s1.conclusion == 'failure'"
  but I believe that if a step fails then the test fails which is not what we want.

   There shouldn't be any side effects w/ this approach, all steps have a conditional on the docs-only check and should work correctly as before in the non-docs file are updated case

    N/A.  Future work generally might include a tag that also skips testing but is not directly related
  • Loading branch information
aaron-prindle committed Jun 17, 2021
1 parent 7f754f6 commit 5806628
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/integration-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,64 +18,83 @@ jobs:
integration_test_partitions: [0, 1, 2, 3]
steps:

# Skip integration tests for `docs`-only changes (only works for PR-based dev workflows like Skaffold's).
# NOTE: grep output is stored in env var with `|| true` as the run command cannot fail or action will fail
- name: Check if only docs changes were made in this PR
run: |
NON_DOCS_FILES_CHANGED=git diff --name-only ${GITHUB_REF##*/}... | grep -v '^docs/' || true
echo "NON_DOCS_FILES_CHANGED=${#NON_DOCS_FILES_CHANGED}" >> $GITHUB_ENV # get the char len of diff output (used later)
- name: Set up Go
if: ${{ env.NON_DOCS_FILES_CHANGED != 0 }}
uses: actions/setup-go@v2
with:
go-version: ^1.14
id: go

- name: Check out code into the Go module directory
if: ${{ env.NON_DOCS_FILES_CHANGED != 0 }}
uses: actions/checkout@v2

- name: Install Kustomize
if: ${{ env.NON_DOCS_FILES_CHANGED != 0 }}
run: |
wget -O kustomize.tar.gz https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${{ matrix.kustomize_version }}/kustomize_v${{ matrix.kustomize_version }}_linux_amd64.tar.gz
sudo tar -xvf kustomize.tar.gz -C /usr/local/bin/
- name: Install Ko
if: ${{ env.NON_DOCS_FILES_CHANGED != 0 }}
run: |
wget -O ko.tar.gz https://github.com/google/ko/releases/download/v${{ matrix.ko_version }}/ko_${{ matrix.ko_version }}_Linux_x86_64.tar.gz
sudo tar -xvf ko.tar.gz -C /usr/local/bin/
- name: Install Kompose
if: ${{ env.NON_DOCS_FILES_CHANGED != 0 }}
run: |
wget -O kompose https://github.com/kubernetes/kompose/releases/download/v${{ matrix.kompose_version }}/kompose-linux-amd64 && chmod +x kompose
sudo mv kompose /usr/local/bin/
- name: Install GCloud
if: ${{ env.NON_DOCS_FILES_CHANGED != 0 }}
run: |
wget -O gcloud.tar.gz https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${{ matrix.gcloud_sdk_version }}-linux-x86_64.tar.gz
tar -xvf gcloud.tar.gz -C ${HOME}/
CLOUDSDK_PYTHON="python2.7" ${HOME}/google-cloud-sdk/install.sh --usage-reporting=false --bash-completion=false --disable-installation-options
echo "${HOME}/google-cloud-sdk/bin" >> $GITHUB_PATH
- name: Configure GCloud with Docker
if: ${{ env.NON_DOCS_FILES_CHANGED != 0 }}
run: gcloud auth configure-docker

- name: Install Container Structure Test
if: ${{ env.NON_DOCS_FILES_CHANGED != 0 }}
run: |
wget -O container-structure-test https://storage.googleapis.com/container-structure-test/v${{ matrix.container_structure_tests_version }}/container-structure-test-linux-amd64 && chmod +x container-structure-test
sudo mv container-structure-test /usr/local/bin/
- name: Setup other files and permissions
if: ${{ env.NON_DOCS_FILES_CHANGED != 0 }}
run: |
sudo chown $(whoami):docker ${HOME}/.docker -R
sudo chmod g+rw ${HOME}/.docker -R
echo '{}' > ${HOME}/.docker/config.json
mkdir -p ${HOME}/.m2/ && cp ./hack/maven/settings.xml ${HOME}/.m2/settings.xml
- name: Install Minikube from minikube master branch @HEAD and start cluster
if: ${{ env.NON_DOCS_FILES_CHANGED != 0 }}
run: |
curl -Lo minikube https://storage.googleapis.com/minikube-builds/master/minikube-linux-amd64
sudo install minikube /usr/local/bin/minikube
minikube start --profile=minikube --driver=docker
- name: Make and install Skaffold binary from current PR
if: ${{ env.NON_DOCS_FILES_CHANGED != 0 }} # non docs files were changed, skaffold build needed
run: |
make
sudo install "${HOME}/work/skaffold/skaffold/out/skaffold" /usr/local/bin/skaffold
- name: Run integration tests
if: ${{ env.NON_DOCS_FILES_CHANGED != 0 }}
run: |
skaffold config set --global collect-metrics false
IT_PARTITION=${{ matrix.integration_test_partitions }} make integration-tests

0 comments on commit 5806628

Please sign in to comment.