-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add CI with shellcheck and Linux target tests. #24
Open
Alexhuszagh
wants to merge
1
commit into
cross-rs:main
Choose a base branch
from
Alexhuszagh:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck disable=SC2086 | ||
|
||
set -e | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck disable=SC2012,SC2086 | ||
|
||
set -e | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.