FreeCAD

Форк
0
/
sub_prepare.yml 
162 строки · 8.3 Кб
1
# SPDX-License-Identifier: LGPL-2.1-or-later
2
# ***************************************************************************
3
# *                                                                         *
4
# *   Copyright (c) 2023 0penBrain.                                         *
5
# *                                                                         *
6
# *   This file is part of FreeCAD.                                         *
7
# *                                                                         *
8
# *   FreeCAD is free software: you can redistribute it and/or modify it    *
9
# *   under the terms of the GNU Lesser General Public License as           *
10
# *   published by the Free Software Foundation, either version 2.1 of the  *
11
# *   License, or (at your option) any later version.                       *
12
# *                                                                         *
13
# *   FreeCAD is distributed in the hope that it will be useful, but        *
14
# *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
15
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      *
16
# *   Lesser General Public License for more details.                       *
17
# *                                                                         *
18
# *   You should have received a copy of the GNU Lesser General Public      *
19
# *   License along with FreeCAD. If not, see                               *
20
# *   <https://www.gnu.org/licenses/>.                                      *
21
# *                                                                         *
22
# ***************************************************************************
23

24
# This is the pre-check workflow for CI of FreeCAD.
25
# It aims at running some basic checks about the workflow run ...
26
# ... and gathering some data needed for the next steps.
27

28
name: Prepare
29

30
on:
31
  workflow_call:
32
    inputs:
33
      artifactBasename:
34
        type: string
35
        required: true
36
      dontFailOnOldRebase:
37
        default: true
38
        type: boolean
39
        required: false
40
      maxRebaseHours:
41
        default: "48"
42
        type: string
43
        required: false
44
    outputs:
45
      reportFile:
46
        value: ${{ jobs.Prepare.outputs.reportFile }}
47
      changedFiles:
48
        value: ${{ jobs.Prepare.outputs.changedFiles }}
49
      changedPythonFiles:
50
        value: ${{ jobs.Prepare.outputs.changedPythonFiles }}
51
      changedCppFiles:
52
        value: ${{ jobs.Prepare.outputs.changedCppFiles }}
53

54
jobs:
55

56
  Prepare:
57
    env:
58
      isPR: ${{ github.event_name == 'pull_request' }}
59
      isPush: ${{ github.event_name == 'push' }}
60
      logdir: /tmp/logs/
61
      reportdir: /tmp/report/
62
      reportfilename: ${{ inputs.artifactBasename }}-report.md
63
    runs-on: ubuntu-latest
64
    defaults:
65
      run:
66
        shell: bash
67
    outputs:
68
      reportFile: ${{ steps.Init.outputs.reportFile }}
69
      changedFiles: ${{ steps.Output.outputs.changedFiles }}
70
      changedPythonFiles: ${{ steps.Output.outputs.changedPythonFiles }}
71
      changedCppFiles: ${{ steps.Output.outputs.changedCppFiles }}
72

73
    steps:
74
      - name: Make needed directories, files and initializations
75
        id: Init
76
        run: |
77
          mkdir -p ${{ env.logdir }}
78
          mkdir -p ${{ env.reportdir }}
79
          commitCnt=0
80
          touch ${{ env.logdir }}changedFiles.lst ${{ env.logdir }}changedCppFiles.lst ${{ env.logdir }}changedPythonFiles.lst
81
          echo "reportFile=${{ env.reportfilename }}" >> $GITHUB_OUTPUT
82
      - name: Determine base and head SHA in case of PR
83
        if: env.isPR == 'true'
84
        run: |
85
          baseSha=${{ github.event.pull_request.base.sha }}
86
          headSha=${{ github.event.pull_request.head.sha }}
87
          echo "baseSha=$baseSha" >> $GITHUB_ENV
88
          echo "headSha=$headSha" >> $GITHUB_ENV
89
          echo "This CI run is performed on a Pull Request" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
90
          echo "Base SHA is $baseSha, Head SHA is $headSha" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
91
      - name: Check if PR has been recently rebased
92
        if: env.isPR == 'true'
93
        continue-on-error: ${{ inputs.dontFailOnOldRebase }}
94
        run: |
95
          baseDate=$(curl -H "Accept: application/vnd.github+json" -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/commits/$baseSha | jq -r '.commit.committer.date')
96
          dateDiff=$(( ( $(date +%s) - $(date -d $baseDate +%s) ) / 3600 ))
97
          echo "Pull request is based on a $dateDiff hour-old commit" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
98
          # Exit the step with appropriate code
99
          if [ $dateDiff -gt ${{ inputs.maxRebaseHours }} ]
100
          then
101
            echo -n ":warning: Pull request should be rebased" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
102
            exit 1
103
          fi
104
      - name: Determine base and head SHA in case of push
105
        if: env.isPush == 'true'
106
        run: |
107
          baseSha=${{ github.event.before }}
108
          headSha=${{ github.event.after }}
109
          echo "headSha=$headSha" >> $GITHUB_ENV
110
          if [ $baseSha -eq 0 ]
111
          then
112
            echo "This CI run is performed on a Push that created a new branch : files changed will be ignored" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
113
            echo "Head SHA is $headSha" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
114
            echo "isPush='false'" >> $GITHUB_ENV
115
          else
116
            echo "This CI run is performed on a Push" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
117
            echo "Base SHA is $baseSha, Head SHA is $headSha" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
118
            echo "baseSha=$baseSha" >> $GITHUB_ENV
119
          fi
120
      - name: Get compare between head and base
121
        if: env.isPR == 'true' || env.isPush == 'true'
122
        run: |
123
          echo "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/compare/$baseSha...$headSha"
124
          curl -H "Accept: application/vnd.github+json" -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/compare/$baseSha...$headSha > ${{ env.logdir }}compare.json
125
      - name: Get number of commits in the changeset
126
        if: env.isPR == 'true' || env.isPush == 'true'
127
        run: |
128
          commitCnt=$(jq -re '.ahead_by' ${{ env.logdir }}compare.json)
129
          echo "Changeset is composed of $commitCnt commit(s)" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
130
      - name: Get files modified in changeset #TODO check what happens with deleted file in the subsequent process
131
        if: env.isPR == 'true' || env.isPush == 'true'
132
        run: |
133
          jq '.files[] | if .status != "removed" then .filename else empty end' ${{ env.logdir }}compare.json > ${{ env.logdir }}changedFiles.lst
134
          grep -E '\.(py|py3)"' ${{ env.logdir }}changedFiles.lst > ${{ env.logdir }}changedPythonFiles.lst || true
135
          grep -E '\.(c|c\+\+|cc|cpp|cu|cuh|cxx|h|h\+\+|hh|hpp|hxx)"' ${{ env.logdir }}changedFiles.lst > ${{ env.logdir }}changedCppFiles.lst || true
136
          # Write the report
137
          echo "::group::Modified files in changeset (removed files are ignored) :" ; cat ${{ env.logdir }}changedFiles.lst ; echo "::endgroup::"
138
          echo "<details><summary>Modified files (removed files are ignored):</summary>" >> ${{env.reportdir}}${{ env.reportfilename }}
139
          cat ${{ env.logdir }}changedFiles.lst >> ${{env.reportdir}}${{ env.reportfilename }}
140
          echo "</details>" >> ${{env.reportdir}}${{ env.reportfilename }}
141
          echo "" >> ${{env.reportdir}}${{ env.reportfilename }}
142
      - name: Transmitting outputs
143
        id: Output
144
        run: |
145
          echo "changedFiles=$(cat ${{ env.logdir }}changedFiles.lst | tr '\n' ' ')" >> $GITHUB_OUTPUT
146
          echo "changedPythonFiles=$(cat ${{ env.logdir }}changedPythonFiles.lst | tr '\n' ' ')" >> $GITHUB_OUTPUT
147
          echo "changedCppFiles=$(cat ${{ env.logdir }}changedCppFiles.lst | tr '\n' ' ')" >> $GITHUB_OUTPUT
148
          echo "" >> $GITHUB_OUTPUT
149
      - name: Upload logs
150
        if: always()
151
        uses: actions/upload-artifact@v4
152
        with:
153
          name: ${{ inputs.artifactBasename }}-Logs
154
          path: |
155
            ${{ env.logdir }}
156
      - name: Upload report
157
        if: always()
158
        uses: actions/upload-artifact@v4
159
        with:
160
          name: ${{ env.reportfilename }}
161
          path: |
162
            ${{env.reportdir}}${{ env.reportfilename }}
163

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.