Skip to content
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
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/actions/setup-rust/action.yml
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]
31 changes: 31 additions & 0 deletions .github/actions/setup-rust/rust.json
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
}
]
}
]
}
71 changes: 71 additions & 0 deletions .github/workflows/ci.yml
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
Copy link
Collaborator Author

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.

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
Copy link
Collaborator Author

@Alexhuszagh Alexhuszagh Oct 24, 2022

Choose a reason for hiding this comment

The 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
1 change: 1 addition & 0 deletions docker/darwin-entry.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC2086

set -e

Expand Down
4 changes: 2 additions & 2 deletions docker/darwin-symlink.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
# shellcheck disable=SC2016
# shellcheck disable=SC2012,SC2016

set -x
set -euo pipefail

main() {
# create a symlink to our sysroot to make it accessible in the dockerfile
local sdk_version
sdk_version=$(ls /opt/osxcross/SDK)
sdk_version=$(ls -t -1 /opt/osxcross/SDK | head -1)
ln -s "/opt/osxcross/SDK/${sdk_version}" "/opt/osxcross/SDK/latest"

rm "${0}"
Expand Down
1 change: 1 addition & 0 deletions docker/darwin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set -eo pipefail
. lib.sh

if [[ "${MACOS_SDK_FILE}" == "nonexistent" ]] && [[ -z "${MACOS_SDK_URL}" ]]; then
# shellcheck disable=SC2016
echo 'Must set the environment variable `MACOS_SDK_FILE` or `MACOS_SDK_URL`.' 1>&2
exit 1
fi
Expand Down
1 change: 1 addition & 0 deletions docker/ios-entry.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC2012,SC2086

set -e

Expand Down
4 changes: 2 additions & 2 deletions docker/ios-symlink.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env bash
# shellcheck disable=SC2016
# shellcheck disable=SC2012,SC2016

set -x
set -euo pipefail

main() {
# create a symlink to our sysroot to make it accessible in the dockerfile
local sdk_version
sdk_version=$(ls /opt/cctools/SDK)
sdk_version=$(ls -t -1 /opt/cctools/SDK | head -1)
ln -s "/opt/cctools/SDK/${sdk_version}" "/opt/cctools/SDK/latest"

rm "${0}"
Expand Down
5 changes: 3 additions & 2 deletions docker/ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# https://github.com/tpoechtrager/cctools-port/tree/master/usage_examples/ios_toolchain
# This code is public domain
# https://github.com/tpoechtrager/cctools-port/issues/21#issuecomment-223382676
# shellcheck disable=SC2012

set -x
set -eo pipefail
Expand All @@ -11,6 +12,7 @@ set -eo pipefail
. lib.sh

if [[ "${IOS_SDK_FILE}" == "nonexistent" ]] && [[ -z "${IOS_SDK_URL}" ]]; then
# shellcheck disable=SC2016
echo 'Must set the environment variable `IOS_SDK_FILE` or `IOS_SDK_URL`.' 1>&2
exit 1
fi
Expand Down Expand Up @@ -95,8 +97,6 @@ main() {
# now, need to get our metadata, and move the SDK to the output dir
mkdir -p "${install_dir}"
mv SDK "${sdk_dir}"
local syslib
syslib=$(find "${sdk_dir}" -name libSystem.dylib -o -name libSystem.tbd | head -n1)
local wrapper_sdkdir
pushd "${sdk_dir}"
wrapper_sdkdir=$(echo iPhoneOS*sdk | head -n1)
Expand Down Expand Up @@ -146,6 +146,7 @@ main() {
ln -sf "${clang}" "${clang}"++

# need a fake wrapper for xcrun, which is used by `cc`.
# shellcheck disable=SC2016
echo '#!/usr/bin/env sh
echo "${SDKROOT}"
' > "${install_dir}/bin/xcrun"
Expand Down
4 changes: 2 additions & 2 deletions docker/msvc-wine-symlink.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# shellcheck disable=SC2016
# shellcheck disable=SC2012,SC2016

set -x
set -euo pipefail
Expand All @@ -19,7 +19,7 @@ main() {

# create a symlink to our sysroot to make it accessible in the dockerfile
local msvc_version
msvc_version=$(ls /opt/msvc/vc/tools/msvc/)
msvc_version=$(ls -t -1 /opt/msvc/vc/tools/msvc/ | head -1)
ln -s "/opt/msvc/vc/tools/msvc/${msvc_version}" "/opt/msvc/vc/tools/msvc/latest"

rm "${0}"
Expand Down
65 changes: 65 additions & 0 deletions run_ci_tests.py
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()
Loading