Switch to unified view

a b/.github/workflows/tests.yml
1
name: Tests and Linting
2
3
on:
4
  workflow_dispatch:
5
  pull_request:
6
  push:
7
    branches: [master]
8
9
env:
10
  UV_INDEX_STRATEGY: "unsafe-first-match"
11
  UV_EXTRA_INDEX_URL: "https://download.pytorch.org/whl/cpu"
12
  PIP_EXTRA_INDEX_URL: "https://download.pytorch.org/whl/cpu"
13
  UV_SYSTEM_PYTHON: 1
14
  BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
15
16
jobs:
17
  linting:
18
    name: Linting
19
    if: github.event_name == 'pull_request'
20
    runs-on: ubuntu-22.04
21
    steps:
22
      - uses: actions/checkout@v3
23
        with:
24
          # requites to grab the history of the PR
25
          fetch-depth: 0
26
27
      - uses: actions/setup-python@v5
28
        with:
29
          cache: 'pip'
30
31
      - uses: pre-commit/action@v3.0.0
32
        with:
33
          extra_args: --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}
34
35
  pytest:
36
    name: Pytest
37
    runs-on: ubuntu-22.04
38
    strategy:
39
      fail-fast: true
40
      matrix:
41
        python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
42
    steps:
43
      - uses: actions/checkout@v2
44
45
      - name: Cache downloaded resources
46
        uses: actions/cache@v3
47
        with:
48
          path: ~/.data/
49
          key: resources
50
51
      - name: Set up Java
52
        uses: actions/setup-java@v2
53
        with:
54
          distribution: "temurin" # See 'Supported distributions' for available options
55
          java-version: "8"
56
57
      - name: Set up Python
58
        uses: actions/setup-python@v5
59
        with:
60
          python-version: ${{ matrix.python-version }}
61
          cache: 'pip'
62
63
      - name: Install dependencies
64
        run: pip install -e ".[dev]"
65
        if: matrix.python-version != '3.9' && matrix.python-version != '3.10' && matrix.python-version != '3.11' && matrix.python-version != '3.12'
66
67
      - name: Install dependencies
68
        run: pip install -e ".[dev,setup]"
69
        if: matrix.python-version == '3.9'
70
71
      - name: Install dependencies
72
        # skip ML tests for 3.10 and 3.11
73
        run: pip install -e ".[dev-no-ml]"
74
        if: matrix.python-version == '3.10' || matrix.python-version == '3.11' || matrix.python-version == '3.12'
75
76
      - name: Test with Pytest on Python ${{ matrix.python-version }}
77
        env:
78
          UMLS_API_KEY: ${{ secrets.UMLS_API_KEY }}
79
        run: coverage run -m pytest --ignore tests/test_docs.py
80
        if: matrix.python-version != '3.9'
81
82
      - name: Test with Pytest on Python ${{ matrix.python-version }}
83
        env:
84
          UMLS_API_KEY: ${{ secrets.UMLS_API_KEY }}
85
        run: coverage run -m pytest
86
        if: matrix.python-version == '3.9'
87
88
      - name: Upload coverage data
89
        uses: actions/upload-artifact@v4
90
        with:
91
          name: coverage-data-${{ matrix.python-version }}
92
          path: .coverage.*
93
          if-no-files-found: ignore
94
          include-hidden-files: true
95
96
  coverage:
97
    name: Coverage
98
    needs: pytest
99
    uses: aphp/foldedtensor/.github/workflows/coverage.yml@main
100
    with:
101
      base-branch: master
102
      coverage-data-pattern: coverage-data-*
103
      coverage-report: coverage.txt
104
      coverage-badge: coverage.svg
105
      coverage-branch: coverage
106
107
  documentation:
108
    name: Documentation
109
    runs-on: ubuntu-latest
110
    # Main docs are built in another workflow, we don't have to test them outside of PR
111
    if: github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch'
112
    steps:
113
    - uses: actions/checkout@v2
114
115
    - uses: actions/setup-python@v5
116
      with:
117
        python-version: 3.9
118
        cache: 'pip'
119
120
    - name: Install dependencies
121
      run: pip install -e ".[docs]"
122
123
    - name: Set up Git
124
      run: |
125
        git config user.name ${{ github.actor }}
126
        git config user.email ${{ github.actor }}@users.noreply.github.com
127
        echo Current branch: $BRANCH_NAME
128
129
    - name: Build documentation
130
      run: |
131
        mike deploy --no-redirect --rebase --update-aliases $BRANCH_NAME latest
132
        mike set-default $BRANCH_NAME
133
134
    - name: Put content of gh-pages to public folder
135
      run: rm -rf public && mkdir public && git archive gh-pages | tar -x -C ./public/
136
137
    - name: Set up Vercel
138
      run: npm install --global vercel@latest
139
140
    - name: Pull Vercel environment
141
      run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
142
143
    - name: Create new vercel project linked to this branch
144
      run: vercel project add edsnlp-$BRANCH_NAME --token=${{ secrets.VERCEL_TOKEN }}
145
146
    - name: Link public folder to the (maybe) new vercel project
147
      run: vercel link --cwd public --project edsnlp-$BRANCH_NAME --yes --token=${{ secrets.VERCEL_TOKEN }}
148
149
    - name: Deploy to Vercel
150
      run: vercel deploy public/ --yes --token=${{ secrets.VERCEL_TOKEN }} --archive=tgz --prod > deployment-url.txt
151
152
    - name: Post the documentation link
153
      env:
154
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155
      run: |
156
        slugify () {
157
            echo "$1" | iconv -c -t ascii//TRANSLIT | sed -E 's/[^a-zA-Z0-9-]+//g' | tr A-Z a-z
158
        }
159
        RAW_PROJECT_NAME="edsnlp-$BRANCH_NAME"
160
        URL=https://$(slugify "$RAW_PROJECT_NAME").vercel.app/
161
        COMMENT_BODY="## Docs preview URL\n\n$URL\n\n"
162
        HEADER="Authorization: token $GITHUB_TOKEN"
163
        PR_COMMENTS_URL="https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments"
164
165
        # Fetch existing comments to find if one from this workflow already exists
166
        COMMENTS=$(curl -s -H "$HEADER" "$PR_COMMENTS_URL")
167
        COMMENT_ID=$(echo "$COMMENTS" | jq -r '.[] | select(.user.login == "github-actions[bot]" and (.body | startswith("## Docs preview URL"))) | .id')
168
169
        # Check if we have a comment ID, if so, update it, otherwise create a new one
170
        if [[ "$COMMENT_ID" ]]; then
171
          # Update existing comment
172
          curl -s -X PATCH -H "$HEADER" -H "Content-Type: application/json" -d "{\"body\": \"$COMMENT_BODY\"}" "https://api.github.com/repos/${{ github.repository }}/issues/comments/$COMMENT_ID"
173
        else
174
          # Post new comment
175
          curl -s -X POST -H "$HEADER" -H "Content-Type: application/json" -d "{\"body\": \"$COMMENT_BODY\"}" "$PR_COMMENTS_URL"
176
        fi
177
178
        if [ $status -ne 0 ]; then
179
          exit $status
180
        fi
181
182
  simple-installation:
183
    name: Simple installation
184
    runs-on: ubuntu-22.04
185
    strategy:
186
      fail-fast: true
187
      matrix:
188
        python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
189
    steps:
190
      - uses: actions/checkout@v2
191
192
      - uses: actions/setup-python@v5
193
        with:
194
          python-version: ${{ matrix.python-version }}
195
          cache: 'pip'
196
197
      - run: echo WEEK=$(date +%V) >>$GITHUB_ENV
198
        shell: bash
199
200
      - name: Install library
201
        run: |
202
          pip install ".[ml]" pytest
203
          pytest tests/pipelines/test_pipelines.py