|
| 1 | +name: "Check amalgamation" |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + |
| 6 | +jobs: |
| 7 | + check: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + env: |
| 10 | + MAIN_DIR: ${{ github.workspace }}/main |
| 11 | + INCLUDE_DIR: ${{ github.workspace }}/main/single_include/nlohmann |
| 12 | + TOOL_DIR: ${{ github.workspace }}/tools/tools/amalgamate |
| 13 | + ASTYLE_FLAGS: > |
| 14 | + --style=allman --indent=spaces=4 --indent-modifiers --indent-switches --indent-preproc-block |
| 15 | + --indent-preproc-define --indent-col1-comments --pad-oper --pad-header --align-pointer=type |
| 16 | + --align-reference=type --add-brackets --convert-tabs --close-templates --lineend=linux --preserve-date |
| 17 | + --formatted |
| 18 | +
|
| 19 | + steps: |
| 20 | + - name: Checkout pull request |
| 21 | + uses: actions/checkout@v3 |
| 22 | + with: |
| 23 | + path: main |
| 24 | + ref: ${{ github.event.pull_request.head.sha }} |
| 25 | + |
| 26 | + - name: Checkout tools |
| 27 | + uses: actions/checkout@v3 |
| 28 | + with: |
| 29 | + path: tools |
| 30 | + ref: develop |
| 31 | + |
| 32 | + - name: Install astyle |
| 33 | + run: | |
| 34 | + sudo apt-get update |
| 35 | + sudo apt-get install astyle |
| 36 | +
|
| 37 | + - name: Check amalgamation |
| 38 | + run: | |
| 39 | + cd $MAIN_DIR |
| 40 | +
|
| 41 | + rm -fr $INCLUDE_DIR/json.hpp~ $INCLUDE_DIR/json_fwd.hpp~ |
| 42 | + cp $INCLUDE_DIR/json.hpp $INCLUDE_DIR/json.hpp~ |
| 43 | + cp $INCLUDE_DIR/json_fwd.hpp $INCLUDE_DIR/json_fwd.hpp~ |
| 44 | +
|
| 45 | + python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json.json -s . |
| 46 | + python3 $TOOL_DIR/amalgamate.py -c $TOOL_DIR/config_json_fwd.json -s . |
| 47 | + echo "Format (1)" |
| 48 | + astyle $ASTYLE_FLAGS --suffix=none --quiet $INCLUDE_DIR/json.hpp $INCLUDE_DIR/json_fwd.hpp |
| 49 | +
|
| 50 | + diff $INCLUDE_DIR/json.hpp~ $INCLUDE_DIR/json.hpp |
| 51 | + diff $INCLUDE_DIR/json_fwd.hpp~ $INCLUDE_DIR/json_fwd.hpp |
| 52 | +
|
| 53 | + astyle $ASTYLE_FLAGS $(find docs/examples include tests -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort) |
| 54 | + echo Check |
| 55 | + find $MAIN_DIR -name '*.orig' -exec false {} \+ |
| 56 | +
|
| 57 | + - name: Comment on pull request |
| 58 | + if: failure() |
| 59 | + uses: actions/github-script@v6 |
| 60 | + with: |
| 61 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 62 | + script: | |
| 63 | + const author = context.payload.pull_request.user.login |
| 64 | + const opts = github.rest.issues.listForRepo.endpoint.merge({ |
| 65 | + owner: context.repo.owner, |
| 66 | + repo: context.repo.repo, |
| 67 | + creator: author, |
| 68 | + state: 'all' |
| 69 | + }) |
| 70 | +
|
| 71 | + let first = true |
| 72 | + const issues = await github.paginate(opts) |
| 73 | + for (const issue of issues) { |
| 74 | + if (issue.number === context.issue.number) { |
| 75 | + continue |
| 76 | + } |
| 77 | +
|
| 78 | + if (issue.pull_request) { |
| 79 | + first = false |
| 80 | + break |
| 81 | + } |
| 82 | + } |
| 83 | +
|
| 84 | + await github.rest.issues.createComment({ |
| 85 | + issue_number: context.issue.number, |
| 86 | + owner: context.repo.owner, |
| 87 | + repo: context.repo.repo, |
| 88 | + body: '## 🔴 Amalgamation check failed! 🔴\nThe source code has not been amalgamated.' |
| 89 | + + (first ? ' @' + author + ' Please read and follow the [Contribution Guidelines]' |
| 90 | + + '(https://github.com/nlohmann/json/blob/develop/.github/CONTRIBUTING.md#files-to-change).' |
| 91 | + : '') |
| 92 | + }) |
0 commit comments