|
| 1 | +# https://docs.github.com/en/actions/using-workflows/reusing-workflows#calling-a-reusable-workflow |
| 2 | +# https://docs.github.com/fr/actions/using-workflows/workflow-syntax-for-github-actions#exemple--inclusion-de-chemins-dacc%C3%A8s |
| 3 | + |
| 4 | +name: Lock dependencies |
| 5 | +on: |
| 6 | + pull_request: |
| 7 | + types: [opened, reopened, synchronize, labeled, unlabeled] |
| 8 | + workflow_dispatch: |
| 9 | +# Concurrency : auto-cancel "old" jobs ie when pushing again |
| 10 | +# https://docs.github.com/fr/actions/using-jobs/using-concurrency |
| 11 | +concurrency: |
| 12 | + group: ${{ github.workflow }}-${{ github.ref || github.run_id }} |
| 13 | + cancel-in-progress: true |
| 14 | +defaults: |
| 15 | + run: |
| 16 | + shell: bash |
| 17 | +permissions: |
| 18 | + pull-requests: write |
| 19 | + contents: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + lock-deps: |
| 23 | + if: ${{ !github.event.pull_request || contains( github.event.pull_request.labels.*.name, 'Lockfile') }} |
| 24 | + name: "Lock dependencies using PDM" |
| 25 | + runs-on: ubuntu-latest |
| 26 | + continue-on-error: false # https://ncorti.com/blog/howto-github-actions-build-matrix |
| 27 | + steps: |
| 28 | + - name: Check if organization member |
| 29 | + id: is_organization_member |
| 30 | + uses: JamesSingleton/[email protected] |
| 31 | + with: |
| 32 | + organization: Giskard-AI |
| 33 | + username: ${{ github.actor }} |
| 34 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + |
| 36 | + - name: Interrupt job |
| 37 | + if: ${{ steps.is_organization_member.outputs.result == 'false' }} |
| 38 | + shell: bash |
| 39 | + run: | |
| 40 | + echo "Job failed due to user not being a member of Giskard-AI organization and the 'safe for build' label not being set on the PR" |
| 41 | + exit 1 |
| 42 | +
|
| 43 | + - name: Extract branch name |
| 44 | + shell: bash |
| 45 | + run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT |
| 46 | + id: extract_branch |
| 47 | + |
| 48 | + - name: Checkout code |
| 49 | + |
| 50 | + with: |
| 51 | + token: ${{ secrets.RELEASE_PAT_TOKEN }} # Needed to trigger other actions |
| 52 | + ref: ${{ steps.extract_branch.outputs.branch }} |
| 53 | + |
| 54 | + - name: Setup PDM |
| 55 | + uses: pdm-project/setup-pdm@v3 |
| 56 | + with: |
| 57 | + python-version: "3.10" |
| 58 | + cache: false |
| 59 | + |
| 60 | + - name: Install dependencies |
| 61 | + run: rm -rf pdm.lock && pdm lock -G :all |
| 62 | + |
| 63 | + - name: Configure git |
| 64 | + run: | |
| 65 | + git config --global user.name 'BotLocker' |
| 66 | + git config --global user.email '[email protected]' |
| 67 | +
|
| 68 | + - name: Adding file |
| 69 | + run: | |
| 70 | + git add pdm.lock |
| 71 | + git commit -m "Regenerating pdm.lock" --allow-empty |
| 72 | +
|
| 73 | + - name: Remove label |
| 74 | + if: ${{ github.event.pull_request}} |
| 75 | + run: | |
| 76 | + gh pr edit --remove-label Lockfile |
| 77 | + env: |
| 78 | + GH_TOKEN: ${{ github.token }} |
| 79 | + |
| 80 | + - name: Push to target branch |
| 81 | + run: | |
| 82 | + git push origin ${{ steps.extract_branch.outputs.branch }} |
| 83 | +
|
0 commit comments