-
Couldn't load subscription status.
- Fork 23
Add CI with shellcheck and Linux target tests. #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: Setup Rust | ||
| description: Setup Rust with specified toolchain, target and components. | ||
| inputs: | ||
| toolchain: | ||
| description: 'Toolchain' | ||
| default: stable | ||
| required: true | ||
| target: | ||
| description: 'Target' | ||
| required: true | ||
| components: | ||
| description: 'Components' | ||
| required: true | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Install Rust toolchain | ||
| uses: dtolnay/rust-toolchain@v1 | ||
| with: | ||
| toolchain: ${{ inputs.toolchain }} | ||
| target: ${{ inputs.target }} | ||
| components: ${{ inputs.components }} | ||
|
|
||
| - name: Install rust matcher | ||
| run: echo "::add-matcher::.github/actions/setup-rust/rust.json" | ||
| shell: bash | ||
|
|
||
| - uses: Swatinem/[email protected] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "problemMatcher": [ | ||
| { | ||
| "owner": "rust", | ||
| "pattern": [ | ||
| { | ||
| "regexp": "^(warning|warn|error)(\\[(.*)\\])?: (.*)$", | ||
| "severity": 1, | ||
| "message": 4, | ||
| "code": 3 | ||
| }, | ||
| { | ||
| "regexp": "^([\\s->=]*(.*):(\\d*):(\\d*)|.*)$", | ||
| "file": 2, | ||
| "line": 3, | ||
| "column": 4 | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "owner": "cross-rs", | ||
| "pattern": [ | ||
| { | ||
| "regexp": "^\\[cross\\] (warning|error): (.*)$", | ||
| "severity": 1, | ||
| "message": 2 | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| on: | ||
| pull_request: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: [main, staging, trying] | ||
| tags: | ||
| - "v*.*.*" | ||
|
|
||
| name: CI | ||
|
|
||
| env: | ||
| CARGO_NET_RETRY: 3 | ||
| CARGO_HTTP_CHECK_REVOKE: false | ||
|
|
||
| jobs: | ||
| shellcheck: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
|
|
||
| - name: Run ShellCheck | ||
| uses: azohra/[email protected] | ||
|
|
||
| build: | ||
| name: Build Check | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - uses: ./.github/actions/setup-rust | ||
|
|
||
| - name: Get Changed Files | ||
| id: files | ||
| uses: Ana06/[email protected] | ||
| with: | ||
| # use JSON so we don't have to worry about filenames with spaces | ||
| format: 'json' | ||
| filter: 'docker/Dockerfile.*' | ||
|
|
||
| - name: Validate Changed Images | ||
| id: images | ||
| run: | | ||
| set -x | ||
| set -e | ||
| # read modified files | ||
| readarray -t added_modified < <(jq -r '.[]' <<<'${{ steps.files.outputs.added_modified }}') | ||
| names=() | ||
| for path in "${added_modified[@]}"; do | ||
| filename=$(basename "${path}") | ||
| if [[ "${filename}" == Dockerfile.*linux* ]]; then | ||
| names+=("${filename/Dockerfile./}") | ||
| fi | ||
| done | ||
| count=${#names[@]} | ||
|
|
||
| # only run if we have any modified targets | ||
| if [[ "${count}" -ne "0" ]]; then | ||
| echo "Building and testing images for ${names}" | ||
|
|
||
| # get and build cross to build our docker images | ||
| home="${PWD}" | ||
| td="$(mktemp -d)" | ||
| cd "${td}" | ||
| git clone https://github.com/cross-rs/cross/ "${td}" | ||
| cargo build -p xtask | ||
|
|
||
| # copy over our project and build our docker images | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it makes any sense to deploy these images, for obvious reasons, but then obviously we don't get cached builds. Not sure if there's a good solution here. Maybe we can save to local file between runs and use it to import the cache? |
||
| cp -a "${home}"/* docker/cross-toolchains/ | ||
| python3 -m pip install toml --user | ||
| echo "${names}" | ||
| docker/cross-toolchains/run_ci_tests.py "${names}" | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #!/usr/bin/env bash | ||
| # shellcheck disable=SC2086 | ||
|
|
||
| set -e | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #!/usr/bin/env bash | ||
| # shellcheck disable=SC2012,SC2086 | ||
|
|
||
| set -e | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import argparse | ||
| import os | ||
| import subprocess | ||
| import toml | ||
|
|
||
| HOME = os.path.dirname(os.path.realpath(__file__)) | ||
|
|
||
| def main(): | ||
| parser = argparse.ArgumentParser(prog='CI') | ||
| parser.add_argument('names', nargs='+') | ||
| parser.add_argument('-e', '--engine', help='the container engine to use') | ||
| parser.add_argument( | ||
| '-v', | ||
| '--verbose', | ||
| action='store_true', | ||
| help='print verbose diagnostic output', | ||
| ) | ||
| args = parser.parse_args() | ||
| if args.engine is None: | ||
| args.engine = os.environ.get('CROSS_CONTAINER_ENGINE', 'docker') | ||
|
|
||
| with open(os.path.join(HOME, 'targets.toml')) as file: | ||
| matrix = toml.loads(file.read()) | ||
| matrix = {i['name']: i for i in matrix['target']} | ||
|
|
||
| for name in args.names: | ||
| target = matrix[name] | ||
| command = [ | ||
| 'cargo', | ||
| 'build-docker-image', | ||
| name, | ||
| '--engine', | ||
| args.engine, | ||
| '--tag', | ||
| 'main' | ||
| ] | ||
| if args.verbose: | ||
| command.append('--verbose') | ||
| print(f'Running build command "{" ".join(command)}"') | ||
| subprocess.run(command, check=True) | ||
|
|
||
| # add our environment and run our tests | ||
| env = dict(os.environ) | ||
| cross_env = {} | ||
| key = f'CROSS_TARGET_{target["target"].upper().replace("-", "_")}_IMAGE' | ||
| image = f'ghcr.io/cross-rs/{target["target"]}:main' | ||
| cross_env[key] = image | ||
| cross_env['TARGET'] = target['target'] | ||
| cross_env['CROSS_CONTAINER_ENGINE'] = args.engine | ||
| for key in ('cpp', 'dylib', 'std', 'build-std', 'run', 'runners'): | ||
| value = target.get(key) | ||
| if value: | ||
| key = key.upper().replace('-', '_') | ||
| if value is True: | ||
| value = '1' | ||
| cross_env[key] = value | ||
| env.update(cross_env) | ||
| if args.verbose: | ||
| print(f'Running test command with env of "{cross_env}"') | ||
| subprocess.run(['ci/test.sh'], env=env, check=True) | ||
|
|
||
| if __name__ == '__main__': | ||
| main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might need a 120 minute timeout, since we use crosstool-ng images for most of these, which have quite a long build time.