|
| 1 | +name: CI Upstream |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + pull_request: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + schedule: |
| 10 | + - cron: "0 0 * * *" # Daily “At 00:00” UTC |
| 11 | + workflow_dispatch: # allows you to trigger the workflow run manually |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 15 | + cancel-in-progress: true |
| 16 | + |
| 17 | +jobs: |
| 18 | + detect-ci-trigger: |
| 19 | + name: detect upstream-dev ci trigger |
| 20 | + runs-on: ubuntu-latest |
| 21 | + if: | |
| 22 | + github.repository == 'xarray-contrib/cf-xarray' |
| 23 | + && (github.event_name == 'push' || github.event_name == 'pull_request') |
| 24 | + outputs: |
| 25 | + triggered: ${{ steps.detect-trigger.outputs.trigger-found }} |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v3 |
| 28 | + with: |
| 29 | + fetch-depth: 2 |
| 30 | + - uses: xarray-contrib/[email protected] |
| 31 | + id: detect-trigger |
| 32 | + with: |
| 33 | + keyword: "[test-upstream]" |
| 34 | + |
| 35 | + upstream-dev: |
| 36 | + name: upstream-dev |
| 37 | + runs-on: ubuntu-latest |
| 38 | + needs: detect-ci-trigger |
| 39 | + if: | |
| 40 | + always() |
| 41 | + && ( |
| 42 | + (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch') |
| 43 | + || needs.detect-ci-trigger.outputs.triggered == 'true' |
| 44 | + ) |
| 45 | + defaults: |
| 46 | + run: |
| 47 | + shell: bash -l {0} |
| 48 | + strategy: |
| 49 | + fail-fast: false |
| 50 | + matrix: |
| 51 | + python-version: ["3.10"] |
| 52 | + outputs: |
| 53 | + artifacts_availability: ${{ steps.status.outputs.ARTIFACTS_AVAILABLE }} |
| 54 | + steps: |
| 55 | + - uses: actions/checkout@v3 |
| 56 | + with: |
| 57 | + fetch-depth: 0 # Fetch all history for all branches and tags. |
| 58 | + - name: Set up conda environment |
| 59 | + uses: mamba-org/provision-with-micromamba@34071ca7df4983ccd272ed0d3625818b27b70dcc |
| 60 | + with: |
| 61 | + environment-file: ci/upstream-dev-env.yml |
| 62 | + environment-name: cf_xarray_test |
| 63 | + extra-specs: | |
| 64 | + python=${{ matrix.python-version }} |
| 65 | + pytest-reportlog |
| 66 | + - name: Install cf-xarray |
| 67 | + run: | |
| 68 | + python -m pip install --no-deps -e . |
| 69 | + - name: Version info |
| 70 | + run: | |
| 71 | + conda info -a |
| 72 | + conda list |
| 73 | + - name: import cf_xarray |
| 74 | + run: | |
| 75 | + python -c 'import cf_xarray' |
| 76 | + - name: Run Tests |
| 77 | + if: success() |
| 78 | + id: status |
| 79 | + run: | |
| 80 | + python -m pytest -n 2 -rf \ |
| 81 | + --report-log output-${{ matrix.python-version }}-log.jsonl \ |
| 82 | + || ( |
| 83 | + echo '::set-output name=ARTIFACTS_AVAILABLE::true' && false |
| 84 | + ) |
| 85 | + - name: Upload artifacts |
| 86 | + if: | |
| 87 | + failure() |
| 88 | + && steps.status.outcome == 'failure' |
| 89 | + && github.event_name == 'schedule' |
| 90 | + && github.repository == 'xarray-contrib/cf-xarray' |
| 91 | + uses: actions/upload-artifact@v3 |
| 92 | + with: |
| 93 | + name: output-${{ matrix.python-version }}-log.jsonl |
| 94 | + path: output-${{ matrix.python-version }}-log.jsonl |
| 95 | + retention-days: 5 |
| 96 | + |
| 97 | + report: |
| 98 | + name: report |
| 99 | + needs: upstream-dev |
| 100 | + if: | |
| 101 | + failure() |
| 102 | + && github.event_name == 'schedule' |
| 103 | + && needs.upstream-dev.outputs.artifacts_availability == 'true' |
| 104 | + runs-on: ubuntu-latest |
| 105 | + defaults: |
| 106 | + run: |
| 107 | + shell: bash |
| 108 | + steps: |
| 109 | + - uses: actions/checkout@v3 |
| 110 | + - uses: actions/setup-python@v4 |
| 111 | + with: |
| 112 | + python-version: "3.x" |
| 113 | + - uses: actions/download-artifact@v3 |
| 114 | + with: |
| 115 | + path: /tmp/workspace/logs |
| 116 | + - name: Move all log files into a single directory |
| 117 | + run: | |
| 118 | + rsync -a /tmp/workspace/logs/output-*/ ./logs |
| 119 | + ls -R ./logs |
| 120 | + - name: install dependencies |
| 121 | + run: | |
| 122 | + python -m pip install pytest |
| 123 | + - name: Parse logs |
| 124 | + run: | |
| 125 | + shopt -s globstar |
| 126 | + python .github/workflows/parse_logs.py logs/**/*-log* |
| 127 | + cat pytest-logs.txt |
| 128 | + - name: Report failures |
| 129 | + uses: actions/github-script@v6 |
| 130 | + with: |
| 131 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 132 | + script: | |
| 133 | + const fs = require('fs'); |
| 134 | + const pytest_logs = fs.readFileSync('pytest-logs.txt', 'utf8'); |
| 135 | + const title = "⚠️ Nightly upstream-dev CI failed ⚠️" |
| 136 | + const workflow_url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}` |
| 137 | + const issue_body = `[Workflow Run URL](${workflow_url})\n${pytest_logs}` |
| 138 | +
|
| 139 | + // Run GraphQL query against GitHub API to find the most recent open issue used for reporting failures |
| 140 | + const query = `query($owner:String!, $name:String!, $creator:String!, $label:String!){ |
| 141 | + repository(owner: $owner, name: $name) { |
| 142 | + issues(first: 1, states: OPEN, filterBy: {createdBy: $creator, labels: [$label]}, orderBy: {field: CREATED_AT, direction: DESC}) { |
| 143 | + edges { |
| 144 | + node { |
| 145 | + body |
| 146 | + id |
| 147 | + number |
| 148 | + } |
| 149 | + } |
| 150 | + } |
| 151 | + } |
| 152 | + }`; |
| 153 | +
|
| 154 | + const variables = { |
| 155 | + owner: context.repo.owner, |
| 156 | + name: context.repo.repo, |
| 157 | + label: 'CI', |
| 158 | + creator: "github-actions[bot]" |
| 159 | + } |
| 160 | + const result = await github.graphql(query, variables) |
| 161 | +
|
| 162 | + // If no issue is open, create a new issue, |
| 163 | + // else update the body of the existing issue. |
| 164 | + if (result.repository.issues.edges.length === 0) { |
| 165 | + github.rest.issues.create({ |
| 166 | + owner: variables.owner, |
| 167 | + repo: variables.name, |
| 168 | + body: issue_body, |
| 169 | + title: title, |
| 170 | + labels: [variables.label] |
| 171 | + }) |
| 172 | + } else { |
| 173 | + github.rest.issues.update({ |
| 174 | + owner: variables.owner, |
| 175 | + repo: variables.name, |
| 176 | + issue_number: result.repository.issues.edges[0].node.number, |
| 177 | + body: issue_body |
| 178 | + }) |
| 179 | + } |
0 commit comments