|
| 1 | +name: Check Commits and Colab Images |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ "master" ] |
| 6 | + pull_request: |
| 7 | + branches: [ "master" ] |
| 8 | + workflow_dispatch: |
| 9 | + schedule: |
| 10 | + - cron: 0 12 */1 * * |
| 11 | + |
| 12 | +jobs: |
| 13 | + check_commits_and_images: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout code |
| 20 | + uses: actions/checkout@v4 |
| 21 | + |
| 22 | + - name: Set up Python |
| 23 | + uses: actions/setup-python@v4 |
| 24 | + with: |
| 25 | + python-version: 3.x |
| 26 | + |
| 27 | + - name: Install dependencies |
| 28 | + run: pip install requests pandas google-cloud-bigquery pyarrow nbformat |
| 29 | + |
| 30 | + - name: Authorize Google Cloud |
| 31 | + uses: google-github-actions/auth@v1 |
| 32 | + with: |
| 33 | + credentials_json: ${{ secrets.SERVICE_ACCOUNT_KEY }} |
| 34 | + create_credentials_file: true |
| 35 | + export_environment_variables: true |
| 36 | + |
| 37 | + - name: Run check-commits.py and check-colab-images.py, preprocess notebooks scripts |
| 38 | + run: | |
| 39 | + python test/src/check-commits.py |
| 40 | + python test/src/check-colab-images.py |
| 41 | + python test/src/preProcessNotebooks.py |
| 42 | +
|
| 43 | + - name: Set result output |
| 44 | + id: set-result |
| 45 | + run: | |
| 46 | + if [[ -f "check_colab_images_result.txt" ]]; then |
| 47 | + RESULT=$(cat "check_colab_images_result.txt") |
| 48 | + echo "RESULT=$RESULT" >> $GITHUB_ENV |
| 49 | + fi |
| 50 | +
|
| 51 | + - name: Free Disk Space (Ubuntu) |
| 52 | + uses: jlumbroso/free-disk-space@main |
| 53 | + with: |
| 54 | + tool-cache: false |
| 55 | + android: true |
| 56 | + dotnet: true |
| 57 | + haskell: true |
| 58 | + large-packages: true |
| 59 | + docker-images: true |
| 60 | + swap-storage: true |
| 61 | + |
| 62 | + - name: Docker login |
| 63 | + uses: docker/login-action@v3 |
| 64 | + with: |
| 65 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 66 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 67 | + |
| 68 | + - name: Pull from GCP and Push Docker image to Docker Hub |
| 69 | + if: env.RESULT == 'true' |
| 70 | + run: | |
| 71 | + docker pull us-docker.pkg.dev/colab-images/public/runtime:latest |
| 72 | + docker tag us-docker.pkg.dev/colab-images/public/runtime:latest imagingdatacommons/idc-testing-colab:latest |
| 73 | + docker push imagingdatacommons/idc-testing-colab:latest |
| 74 | +
|
| 75 | + - name: Pull Docker image from Docker Hub |
| 76 | + if: env.RESULT == 'false' |
| 77 | + run: | |
| 78 | + docker pull imagingdatacommons/idc-testing-colab:latest |
| 79 | + |
| 80 | + - name: Copy Google Cloud credentials to Docker container |
| 81 | + run: | |
| 82 | + CREDENTIALS_FILE_PATH="${{ env.GOOGLE_APPLICATION_CREDENTIALS }}" |
| 83 | + CREDENTIALS_FILE_NAME=$(basename "$CREDENTIALS_FILE_PATH") |
| 84 | + GOOGLE_APPLICATION_CREDENTIALS="/content/$CREDENTIALS_FILE_NAME" |
| 85 | + echo "GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS" >> $GITHUB_ENV |
| 86 | + |
| 87 | + - name: Run notebook with papermill |
| 88 | + run: | |
| 89 | + for nb in part1_prerequisites part2_searching_basics part3_exploring_cohorts; do |
| 90 | + docker run -d --name colab -v "$(pwd):/content" -e GOOGLE_APPLICATION_CREDENTIALS="${{ env.GOOGLE_APPLICATION_CREDENTIALS }}" imagingdatacommons/idc-testing-colab:latest |
| 91 | + docker exec -t colab /bin/bash -c "pip install papermill" |
| 92 | + docker exec -t colab /bin/bash -c "set -o xtrace && set -o errexit && set -o pipefail && set -o nounset && set +o errexit && cd content/ && papermill /content/notebooks/getting_started/${nb}.ipynb /content/test/outputs/${nb}_papermill_output.ipynb && set -o errexit && ls -A" |
| 93 | + #docker exec -t colab /bin/bash -c "jupyter nbconvert --to html --ExtractOutputPreprocessor.enabled=False /content/test/outputs/output_${nb}.ipynb" |
| 94 | + docker stop colab |
| 95 | + docker rm colab |
| 96 | + done |
| 97 | + |
| 98 | + - name: Commit changes |
| 99 | + if: ${{ github.event_name != 'pull_request' }} |
| 100 | + uses: stefanzweifel/git-auto-commit-action@v4 |
| 101 | + with: |
| 102 | + commit_message: 'Check colab env' |
| 103 | + file_pattern: 'test/*.csv test/outputs/*.ipynb' |
| 104 | + branch: 'master' |
| 105 | + |
| 106 | + #- name: Check output notebooks for errors |
| 107 | + # run: | |
| 108 | + # for nb in part1_prerequisites part2_searching_basics part3_exploring_cohorts; do |
| 109 | + # if grep -q '"name": "stderr"\|"status": "failed"' test/outputs/output_${nb}.ipynb; then |
| 110 | + # echo "Error messages found in the ${nb} notebook output:" |
| 111 | + # cat test/outputs/output_${nb}.ipynb |
| 112 | + # exit 1 |
| 113 | + # else |
| 114 | + # echo "No errors found in the ${nb} notebook output." |
| 115 | + # fi |
| 116 | + # done |
| 117 | + # exit $EXIT_CODE |
0 commit comments