|
| 1 | +name: CI |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - master |
| 6 | + pull_request: |
| 7 | + branches: |
| 8 | + - master |
| 9 | + schedule: |
| 10 | + - cron: "0 0 * * *" # Daily “At 00:00” UTC |
| 11 | + workflow_dispatch: # allows you to trigger the workflow run manually |
| 12 | + |
| 13 | +jobs: |
| 14 | + upstream-dev: |
| 15 | + name: upstream-dev |
| 16 | + runs-on: ubuntu-latest |
| 17 | + defaults: |
| 18 | + run: |
| 19 | + shell: bash -l {0} |
| 20 | + strategy: |
| 21 | + fail-fast: false |
| 22 | + matrix: |
| 23 | + python-version: ["3.8"] |
| 24 | + steps: |
| 25 | + - name: Cancel previous runs |
| 26 | + |
| 27 | + with: |
| 28 | + access_token: ${{ github.token }} |
| 29 | + - uses: actions/checkout@v2 |
| 30 | + - uses: conda-incubator/setup-miniconda@v2 |
| 31 | + with: |
| 32 | + channels: conda-forge |
| 33 | + mamba-version: "*" |
| 34 | + activate-environment: xarray-tests |
| 35 | + auto-update-conda: false |
| 36 | + python-version: ${{ matrix.python-version }} |
| 37 | + - name: Set up conda environment |
| 38 | + run: | |
| 39 | + mamba env update -f ci/requirements/py38.yml |
| 40 | + bash ci/install-upstream-wheels.sh |
| 41 | + conda list |
| 42 | + - name: Run Tests |
| 43 | + run: | |
| 44 | + python -m pytest --verbose -rf > output-${{ matrix.python-version }}-log |
| 45 | +
|
| 46 | + - name: Upload artifacts |
| 47 | + if: "failure()&&(github.event_name == 'schedule')&&(github.repository == 'pydata/xarray')" # Check the exit code of previous step |
| 48 | + uses: actions/upload-artifact@v2 |
| 49 | + with: |
| 50 | + name: output-${{ matrix.python-version }}-log |
| 51 | + path: output-${{ matrix.python-version }}-log |
| 52 | + retention-days: 5 |
| 53 | + |
| 54 | + report: |
| 55 | + name: report |
| 56 | + needs: upstream-dev |
| 57 | + if: "always()&&(github.event_name == 'schedule')&&(github.repository == 'pydata/xarray')" |
| 58 | + runs-on: ubuntu-latest |
| 59 | + defaults: |
| 60 | + run: |
| 61 | + shell: bash |
| 62 | + steps: |
| 63 | + - uses: actions/checkout@v2 |
| 64 | + - uses: actions/setup-python@v2 |
| 65 | + with: |
| 66 | + python-version: "3.x" |
| 67 | + - uses: actions/download-artifact@v2 |
| 68 | + with: |
| 69 | + path: /tmp/workspace/logs |
| 70 | + - name: Move all log files into a single directory |
| 71 | + run: | |
| 72 | + rsync -a /tmp/workspace/logs/output-*/ ./logs |
| 73 | + ls -R ./logs |
| 74 | + - name: Parse logs |
| 75 | + run: | |
| 76 | + python .github/workflows/parse_logs.py |
| 77 | + - name: Report failures |
| 78 | + uses: actions/github-script@v3 |
| 79 | + with: |
| 80 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 81 | + script: | |
| 82 | + const fs = require('fs'); |
| 83 | + const pytest_logs = fs.readFileSync('pytest-logs.txt', 'utf8'); |
| 84 | + const title = "⚠️ Nightly upstream-dev CI failed ⚠️" |
| 85 | + const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}` |
| 86 | + const issue_body = `[Workflow Run URL](${workflow_url})\n${pytest_logs}` |
| 87 | + |
| 88 | + // Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures |
| 89 | + const query = `query($owner:String!, $name:String!, $creator:String!, $label:String!){ |
| 90 | + repository(owner: $owner, name: $name) { |
| 91 | + issues(first: 1, states: OPEN, filterBy: {createdBy: $creator, labels: [$label]}, orderBy: {field: CREATED_AT, direction: DESC}) { |
| 92 | + edges { |
| 93 | + node { |
| 94 | + body |
| 95 | + id |
| 96 | + number |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + } |
| 101 | + }`; |
| 102 | +
|
| 103 | + const variables = { |
| 104 | + owner: context.repo.owner, |
| 105 | + name: context.repo.repo, |
| 106 | + label: 'CI', |
| 107 | + creator: "github-actions[bot]" |
| 108 | + } |
| 109 | + const result = await github.graphql(query, variables) |
| 110 | + const issue_info = result.repository.issues.edges[0].node |
| 111 | +
|
| 112 | + // If no issue is open, create a new issue, else update the |
| 113 | + // body of the existing issue. |
| 114 | + if (typeof issue_info.number === 'undefined') { |
| 115 | + github.issues.create({ |
| 116 | + owner: variables.owner, |
| 117 | + repo: variables.name, |
| 118 | + body: issue_body, |
| 119 | + title: title, |
| 120 | + labels: [variables.label] |
| 121 | + }) |
| 122 | + } else { |
| 123 | + github.issues.update({ |
| 124 | + owner: variables.owner, |
| 125 | + repo: variables.name, |
| 126 | + issue_number: issue_info.number, |
| 127 | + body: issue_body |
| 128 | + }) |
| 129 | + } |
0 commit comments