|
| 1 | +name: Run Tests |
| 2 | + |
| 3 | +env: |
| 4 | + GIT_AUTHOR_EMAIL: "[email protected]" |
| 5 | + GIT_AUTHOR_NAME: "ci.datadog-api-spec" |
| 6 | + |
| 7 | +on: |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - master |
| 11 | + # schedule: |
| 12 | + # - cron: "0 1 * * *" |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: unit-${{ github.head_ref }} |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + pre-commit: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + if: > |
| 22 | + (github.event.pull_request.draft == false && |
| 23 | + !contains(github.event.pull_request.labels.*.name, 'ci/skip') && |
| 24 | + !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) || |
| 25 | + github.event_name == 'schedule' |
| 26 | + steps: |
| 27 | + # - name: Get GitHub App token |
| 28 | + # id: get_token |
| 29 | + # uses: tibdex/github-app-token@v1 |
| 30 | + # with: |
| 31 | + # app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }} |
| 32 | + # private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }} |
| 33 | + - uses: actions/checkout@v3 |
| 34 | + with: |
| 35 | + fetch-depth: 0 |
| 36 | + ref: ${{ github.event.pull_request.head.sha }} |
| 37 | + # token: ${{ steps.get_token.outputs.token }} |
| 38 | + - name: Install pre-commit |
| 39 | + run: python -m pip install pre-commit |
| 40 | + - name: set PY |
| 41 | + run: echo "PY=$(python -c 'import platform;print(platform.python_version())')" >> $GITHUB_ENV |
| 42 | + - uses: actions/cache@v3 |
| 43 | + with: |
| 44 | + path: ~/.cache/pre-commit |
| 45 | + key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} |
| 46 | + - id: pre_commit |
| 47 | + name: Run pre-commit |
| 48 | + if: github.event.action != 'closed' && github.event.pull_request.merged != true |
| 49 | + run: | |
| 50 | + pre-commit run --from-ref "${FROM_REF}" --to-ref "${TO_REF}" --show-diff-on-failure --color=always |
| 51 | + env: |
| 52 | + FROM_REF: ${{ github.event.pull_request.base.sha }} |
| 53 | + TO_REF: ${{ github.event.pull_request.head.sha }} |
| 54 | + # - name: Commit changes |
| 55 | + # if: ${{ failure() }} |
| 56 | + # run: |- |
| 57 | + # git add -A |
| 58 | + # git config user.name "${GIT_AUTHOR_NAME}" |
| 59 | + # git config user.email "${GIT_AUTHOR_EMAIL}" |
| 60 | + # git commit -m "pre-commit fixes" |
| 61 | + # git push origin "HEAD:${HEAD_REF}" |
| 62 | + # exit 1 |
| 63 | + # env: |
| 64 | + # HEAD_REF: ${{ github.event.pull_request.head.ref }} |
| 65 | + - id: pre_commit_schedule |
| 66 | + name: Run pre-commit in schedule |
| 67 | + if: github.event_name == 'schedule' |
| 68 | + run: | |
| 69 | + pre-commit run --all-files --show-diff-on-failure --color=always |
| 70 | +
|
| 71 | + test: |
| 72 | + strategy: |
| 73 | + matrix: |
| 74 | + rust-version: ["stable"] |
| 75 | + platform: [ubuntu-latest] |
| 76 | + runs-on: ${{ matrix.platform }} |
| 77 | + if: (github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'ci/skip') && !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) || github.event_name == 'schedule' |
| 78 | + steps: |
| 79 | + - name: Checkout code |
| 80 | + uses: actions/checkout@v3 |
| 81 | + - name: Install Rust |
| 82 | + uses: dtolnay/rust-toolchain@master |
| 83 | + with: |
| 84 | + toolchain: ${{ matrix.rust-version }} |
| 85 | + - name: Test |
| 86 | + run: cargo build |
| 87 | + |
| 88 | + # examples: |
| 89 | + # runs-on: ubuntu-latest |
| 90 | + # if: (github.event.pull_request.draft == false && !contains(github.event.pull_request.labels.*.name, 'ci/skip') && !contains(github.event.pull_request.head.ref, 'datadog-api-spec/test/')) || github.event_name == 'schedule' |
| 91 | + # steps: |
| 92 | + # - uses: actions/checkout@v3 |
| 93 | + # - name: Install Rust |
| 94 | + # uses: dtolnay/rust-toolchain@master |
| 95 | + # with: |
| 96 | + # toolchain: ${{ matrix.rust-version }} |
| 97 | + # - name: Check examples |
| 98 | + # run: ./check-examples.sh |
| 99 | + # shell: bash |
| 100 | + |
| 101 | + # report: |
| 102 | + # runs-on: ubuntu-latest |
| 103 | + # if: always() && github.event_name == 'pull_request' && contains(github.event.pull_request.head.ref, 'datadog-api-spec/generated/') |
| 104 | + # needs: |
| 105 | + # - test |
| 106 | + # - examples |
| 107 | + # steps: |
| 108 | + # - name: Get GitHub App token |
| 109 | + # if: github.event_name == 'pull_request' |
| 110 | + # id: get_token |
| 111 | + # uses: tibdex/github-app-token@v1 |
| 112 | + # with: |
| 113 | + # app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }} |
| 114 | + # private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }} |
| 115 | + # repository: DataDog/datadog-api-spec |
| 116 | + # - name: Post status check |
| 117 | + # uses: DataDog/github-actions/post-status-check@v2 |
| 118 | + # with: |
| 119 | + # github-token: ${{ steps.get_token.outputs.token }} |
| 120 | + # repo: datadog-api-spec |
| 121 | + # status: ${{ (needs.test.result == 'cancelled' || needs.examples.result == 'cancelled') && 'pending' || needs.test.result == 'success' && needs.examples.result == 'success' && 'success' || 'failure' }} |
| 122 | + # context: unit |
0 commit comments