diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8495648..5bd0f17 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,34 +3,51 @@ name: build on: pull_request: branches: [ "main" ] - merge_group: - types: [ checks_requested ] + push: + branches: [ "main" ] -jobs: +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true +jobs: changed-files: name: changed-files runs-on: ubuntu-latest outputs: - src: ${{ steps.changed-files-yaml.outputs.src_any_changed }} - lightweight: ${{ steps.changed-files-yaml.outputs.lightweight_any_changed }} - miri: ${{ steps.changed-files-yaml.outputs.miri_any_changed }} + simulator: ${{ steps.changed-files-yaml.outputs.simulator_any_changed }} + soem: ${{ steps.changed-files-yaml.outputs.soem_any_changed }} + twincat: ${{ steps.changed-files-yaml.outputs.twincat_any_changed }} + main: ${{ steps.changed-files-yaml.outputs.main_any_changed }} steps: - uses: actions/checkout@v4 - id: changed-files-yaml uses: tj-actions/changed-files@v44 with: files_yaml: | - src: - - '**/*.rs' - - '**/Cargo.toml' + simulator: + - 'simulator/**/*.rs' + - 'simulator/Cargo.toml' + soem: + - 'SOEMAUTDServer/**/*.rs' + - 'SOEMAUTDServer/Cargo.toml' + twincat: + - 'TwinCATAUTDServerLightweight/**/*.rs' + - 'TwinCATAUTDServerLightweight/Cargo.toml' + main: + - 'src-tauri/**/*.rs' + - 'src-tauri/Cargo.toml' + - 'src/**/*.svelte' - '**/*.ts' - - '**/*.svelte' + - '**/*.js' + - '**/*.html' - 'package.json' + - 'tsconfig.json' + - 'tsconfig.node.json' - test: + test-simulator: needs: changed-files - name: test-on-${{ matrix.os }} + name: test-simulator-on-${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -38,18 +55,95 @@ jobs: os: [macos-latest, ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v4 - if: ${{ needs.changed-files.outputs.src == 'true' }} + if: ${{ needs.changed-files.outputs.simulator == 'true' }} - uses: ./.github/actions/setup-build with: os: ${{ matrix.os }} - if: ${{ needs.changed-files.outputs.src == 'true' }} + if: ${{ needs.changed-files.outputs.simulator == 'true' }} + - run: | + python3 build.py build --simulator + python3 build.py lint --simulator + if: ${{ needs.changed-files.outputs.simulator == 'true' }} + + test-soem: + needs: changed-files + name: test-soem-on-${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v4 + if: ${{ needs.changed-files.outputs.soem == 'true' }} + - uses: ./.github/actions/setup-build + with: + os: ${{ matrix.os }} + if: ${{ needs.changed-files.outputs.soem == 'true' }} + - run: | + python3 build.py build --soem + python3 build.py lint --soem + if: ${{ needs.changed-files.outputs.soem == 'true' }} + + test-twincat: + needs: changed-files + name: test-twincat-on-${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v4 + if: ${{ needs.changed-files.outputs.twincat == 'true' }} + - uses: ./.github/actions/setup-build + with: + os: ${{ matrix.os }} + if: ${{ needs.changed-files.outputs.twincat == 'true' }} + - run: | + python3 build.py build --twincat + python3 build.py lint --twincat + if: ${{ needs.changed-files.outputs.twincat == 'true' }} + + test-main: + needs: changed-files + name: test-main-on-${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v4 + if: ${{ needs.changed-files.outputs.main == 'true' }} + - uses: ./.github/actions/setup-build + with: + os: ${{ matrix.os }} + if: ${{ needs.changed-files.outputs.main == 'true' }} - uses: actions/setup-node@v4 with: node-version: 'lts/*' cache: 'npm' cache-dependency-path: package-lock.json - if: ${{ needs.changed-files.outputs.src == 'true' }} + if: ${{ needs.changed-files.outputs.main == 'true' }} - run: | - python3 build.py build - python3 build.py lint - if: ${{ needs.changed-files.outputs.src == 'true' }} + python3 build.py build --main + python3 build.py lint --main + if: ${{ needs.changed-files.outputs.main == 'true' }} + + auto-merge: + needs: + - test-simulator + - test-soem + - test-twincat + - test-main + permissions: + pull-requests: write + contents: write + runs-on: ubuntu-latest + if: ${{ always() && !cancelled() && !failure() && github.actor == 'dependabot[bot]' }} + steps: + - run: gh pr merge --rebase --auto "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/build.py b/build.py index eebf4c6..2301f97 100644 --- a/build.py +++ b/build.py @@ -135,50 +135,93 @@ def server_build(args): shell = True if config.is_windows() else False - with working_dir("simulator"): - subprocess.run( - [ - "cargo", - "build", - "--release", - "--features", - "unity", - ] - ).check_returncode() - if config.is_windows(): - shutil.copy( - "target/release/simulator.exe", - "target/release/simulator-unity.exe", - ) - else: - shutil.copy( - "target/release/simulator", - "target/release/simulator-unity", - ) + if args.simulator: + with working_dir("simulator"): + subprocess.run( + [ + "cargo", + "build", + "--release", + "--features", + "unity", + ] + ).check_returncode() + if config.is_windows(): + shutil.copy( + "target/release/simulator.exe", + "target/release/simulator-unity.exe", + ) + else: + shutil.copy( + "target/release/simulator", + "target/release/simulator-unity", + ) + + with working_dir("simulator"): + subprocess.run(["cargo", "build", "--release"]).check_returncode() + + if args.soem: + with working_dir("SOEMAUTDServer"): + subprocess.run(["cargo", "build", "--release"]).check_returncode() + + if args.twincat: + with working_dir("TwinCATAUTDServerLightweight"): + subprocess.run(["cargo", "build", "--release"]).check_returncode() - with working_dir("simulator"): - subprocess.run(["cargo", "build", "--release"]).check_returncode() + if args.main: + subprocess.run(["npm", "install"], shell=shell).check_returncode() - with working_dir("SOEMAUTDServer"): - subprocess.run(["cargo", "build", "--release"]).check_returncode() + def create_dummy_if_not_exists(file): + if config.is_windows(): + file += ".exe" + if not os.path.exists(file): + with open(file, "w") as f: + f.write("") - with working_dir("TwinCATAUTDServerLightweight"): - subprocess.run(["cargo", "build", "--release"]).check_returncode() + create_dummy_if_not_exists("target/release/simulator-unity") + create_dummy_if_not_exists("target/release/simulator") + create_dummy_if_not_exists("target/release/SOEMAUTDServer") + create_dummy_if_not_exists("target/release/TwinCATAUTDServerLightweight") - subprocess.run(["npm", "install"], shell=shell).check_returncode() - if not args.external_only: subprocess.run(["npm", "run", "tauri", "build"], shell=shell).check_returncode() def server_lint(args): - with working_dir("."): - command = ["cargo", "clippy"] - command.append("--tests") - command.append("--workspace") - command.append("--") - command.append("-D") - command.append("warnings") - subprocess.run(command).check_returncode() + if args.simulator: + with working_dir("simulator"): + command = ["cargo", "clippy"] + command.append("--tests") + command.append("--") + command.append("-D") + command.append("warnings") + subprocess.run(command).check_returncode() + + if args.soem: + with working_dir("SOEMAUTDServer"): + command = ["cargo", "clippy"] + command.append("--tests") + command.append("--") + command.append("-D") + command.append("warnings") + subprocess.run(command).check_returncode() + + if args.twincat: + with working_dir("TwinCATAUTDServerLightweight"): + command = ["cargo", "clippy"] + command.append("--tests") + command.append("--") + command.append("-D") + command.append("warnings") + subprocess.run(command).check_returncode() + + if args.main: + with working_dir("src-tauri"): + command = ["cargo", "clippy"] + command.append("--tests") + command.append("--") + command.append("-D") + command.append("warnings") + subprocess.run(command).check_returncode() def server_clear(args): @@ -321,14 +364,33 @@ def command_help(args): # build parser_server_build = subparsers.add_parser("build", help="see `build -h`") parser_server_build.add_argument( - "--external-only", - action="store_true", - help="build external dependencies only", + "--simulator", action="store_true", help="build simulator" + ) + parser_server_build.add_argument( + "--soem", action="store_true", help="build SOEM Server" + ) + parser_server_build.add_argument( + "--twincat", action="store_true", help="build TwinCAT Server" + ) + parser_server_build.add_argument( + "--main", action="store_true", help="build main app" ) parser_server_build.set_defaults(handler=server_build) # lint parser_server_lint = subparsers.add_parser("lint", help="see `lint -h`") + parser_server_lint.add_argument( + "--simulator", action="store_true", help="build simulator" + ) + parser_server_lint.add_argument( + "--soem", action="store_true", help="build SOEM Server" + ) + parser_server_lint.add_argument( + "--twincat", action="store_true", help="build TwinCAT Server" + ) + parser_server_lint.add_argument( + "--main", action="store_true", help="build main app" + ) parser_server_lint.set_defaults(handler=server_lint) # server clear