Skip to content

Commit

Permalink
update build action
Browse files Browse the repository at this point in the history
  • Loading branch information
s5suzuki committed Jul 29, 2024
1 parent 4e4dfec commit f7ceccf
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 57 deletions.
130 changes: 112 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,147 @@ 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
matrix:
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}}
140 changes: 101 additions & 39 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f7ceccf

Please sign in to comment.