Skip to content

Commit

Permalink
Try #829:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Jun 22, 2022
2 parents 05c4490 + 502e1ac commit a9223a8
Show file tree
Hide file tree
Showing 9 changed files with 170 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .github/actions/cargo-install-upload-artifacts/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ runs:
--root ${{ steps.metadata.outputs.out-dir }}
--bins
use-cross: true
env:
RUSTFLAGS: "" # Make sure to unset RUSTFLAGS

- name: Archive artifacts
id: archive
Expand Down
65 changes: 65 additions & 0 deletions .github/actions/cargo-llvm-cov/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: llvm coverage
description: Sets up everything that is needed for coverage. Makes artifacts available for processing later, prefixed with cov-
inputs:
name:
description: 'the name of the artifact'
required: true
outputs:
artifact-name:
description: 'the name of the artifact'
value: ${{ steps.cov.outputs.artifact-name }}
runs:
using: composite
steps:
- name: Install cargo-llvm-cov
uses: taiki-e/install-action@v1
with:
tool: cargo-llvm-cov
- run: rustup component add llvm-tools-preview
shell: bash
- name: llvm coverage
id: cov
uses: ./.github/actions/post
if: always()
with:
main: |
pwd=$(pwd)
if which cygpath; then
pwd="$(cygpath -w "$(pwd)")"
fi
echo RUSTFLAGS=" -C instrument-coverage --remap-path-prefix ${pwd}=" >> $GITHUB_ENV
echo LLVM_PROFILE_FILE="${pwd}/target/cross-%m.profraw" >> $GITHUB_ENV
echo CARGO_INCREMENTAL="0" >> $GITHUB_ENV
echo RUST_TEST_THREADS="1" >> $GITHUB_ENV
echo "::set-output name=artifact-name::coverage-${name}"
post: |
# TODO: Only run on success?
# No pwd needed here, we're in the root
export LLVM_PROFILE_FILE="target/cross-%m.profraw"
export CARGO_LLVM_COV_TARGET_DIR="target"
mkdir coverage
echo $(ls target)
cargo llvm-cov --no-run --remap-path-prefix --lcov --output-path "coverage/lcov.${name}.info" -vv || ( echo "::error title=Coverage failed::" && exit 0 )
cargo llvm-cov --no-run --remap-path-prefix --json --output-path "coverage/${name}.json" -vv || true
rm target/*.profraw
npm install @actions/artifact
npm install glob
cat <<-EOT | node - || ( echo "::error title=Coverage upload failed::" && exit 0 )
(async function main() {
var artifact = require('@actions/artifact');
var glob = require('glob')
const artifactClient = artifact.create();
const artifactName = 'coverage-' + process.env.name;
const files = glob.sync("coverage/*");
if (!files.length) {
process.exit(0);
}
console.log("${files}")
const options = { retentionDays: 2 };
const upload = await artifactClient.uploadArtifact(artifactName, files, "coverage", options);
})()
EOT
env:
name: ${{ inputs.name }}
4 changes: 2 additions & 2 deletions .github/actions/cargo-publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ runs:
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}

- name: Create GitHub release
if: >
github.event_name == 'push' && (
Expand All @@ -54,7 +54,7 @@ runs:
prerelease: ${{ startsWith(github.ref, 'refs/tags/v') && contains(github.ref_name, '-') }}
draft: ${{ !startsWith(github.ref, 'refs/tags/v') && steps.changelog-reader.outputs.status == 'unreleased' }}
files: |
${{ steps.download-artifacts.outputs.download-path }}/*/*
${{ steps.download-artifacts.outputs.download-path }}/cross-*/*
- name: Publish crate
uses: actions-rs/cargo@v1
Expand Down
14 changes: 14 additions & 0 deletions .github/actions/post/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# adapted from https://github.com/actions/runner/issues/1478
name: With post step
description: 'Generic JS Action to execute a main command and set a command in a post step.'
inputs:
main:
description: 'Main command/script.'
required: true
post:
description: 'Post command/script.'
required: true
runs:
using: 'node16'
main: 'main.js'
post: 'main.js'
26 changes: 26 additions & 0 deletions .github/actions/post/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// adapted from https://github.com/actions/runner/issues/1478
const { exec } = require("child_process");

function run(cmd) {
exec(cmd, { shell: "bash" }, (error, stdout, stderr) => {
if (stdout.length != 0) {
console.log(`${stdout}`);
}
if (stderr.length != 0) {
console.error(`${stderr}`);
}
if (error) {
process.exitCode = error.code;
console.error(`${error}`);
}
});
}

if (process.env[`STATE_POST`] != undefined) {
// Are we in the 'post' step?
run(process.env.INPUT_POST);
} else {
// Otherwise, this is the main step
console.log(`::save-state name=POST::true`);
run(process.env.INPUT_MAIN);
}
2 changes: 1 addition & 1 deletion .github/actions/setup-rust/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Setup Rust with specified toolchain, target and components.
inputs:
toolchain:
description: 'Toolchain'
default: 1.58.1
default: 1.60.0
required: true
target:
description: 'Target'
Expand Down
12 changes: 12 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
comment: false
coverage:
status:
project:
default:
informational: true
patch:
default:
informational: true
flag_management:
default_rules: # the rules that will be followed for any flag added, generally
carryforward: true
49 changes: 47 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ jobs:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-rust
- uses: ./.github/actions/cargo-llvm-cov
with:
name: test-${{matrix.os}}

- name: Run unit tests
uses: actions-rs/cargo@v1
Expand Down Expand Up @@ -209,6 +212,7 @@ jobs:
outputs:
has-image: ${{ steps.prepare-meta.outputs.has-image }}
images: ${{ steps.build-docker-image.outputs.images && fromJSON(steps.build-docker-image.outputs.images) }}
coverage-artifact: ${{ steps.cov.outputs.artifact-name }}
steps:
- uses: actions/checkout@v3

Expand All @@ -217,10 +221,15 @@ jobs:
- name: Set up Docker Buildx
if: runner.os == 'Linux'
uses: docker/setup-buildx-action@v1

- name: Setup coverage
id: cov
uses: ./.github/actions/cargo-llvm-cov
if: steps.prepare-meta.outputs.has-image && (github.ref == 'refs/heads/staging' || github.ref == 'refs/heads/trying')
with:
name: cross-${{matrix.pretty}}
- name: Install cross
if: matrix.deploy
run: cargo install --path . --force
run: cargo install --path . --force --debug

- name: Build xtask
run: cargo build -p xtask
Expand Down Expand Up @@ -322,3 +331,39 @@ jobs:
"$(jq -r 'all(.result as $result | (["success", "skipped"] | contains([$result])))' <<< "${needs}")"
env:
needs: ${{ toJson(needs) }}

code-cov:
name: Coverage
needs: [test, build, conclusion, generate-matrix]
# should check that there are any artifacts, if not skip
if: always() && (needs.build.result == 'success' || needs.build.result == 'skipped') && needs.test.result == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup-rust
- uses: actions/download-artifact@v3
with:
path: ${{ runner.temp }}/artifacts
- name: Grab PR number
run: echo "::set-output name=pr::"$(echo $commit_message | sed -ne 's/.*\#\(.*\):/\1/p')
id: pr-number
if: ${{ !github.event.pull_request.number }}
env:
commit_message: >
${{
((
startsWith(github.event.head_commit.message, 'Try #') &&
github.event.head_commit.author.username == 'bors[bot]'
) && github.event.head_commit.message) || ''
}}
- name: Upload to codecov.io
run: |
set -x
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
sha_rev=$(git rev-parse HEAD)
find ${artifacts} -name "lcov.*.info" -exec ./codecov -F $(echo {} | sed -n 's/lcov\.\(.*\)\.info/\1/p') \
${pr:+-P ${pr}} -f {} --sha ${sha_rev} -n $(echo {} | sed -n 's/lcov\.\(.*\)\.info/\1/p') \;
env:
pr: ${{ steps.pr-number.outputs.pr || '' }}
artifacts: ${{ runner.temp }}/artifacts
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).

### Internal

- Change rust edition to 2021 and bump MSRV for the cross binary to 1.60.0
- #828 - assume paths are Unicode and provide better error messages for path encoding errors.
- #787 - add installer for git hooks.
- #786, #791 - Migrate build script to rust: `cargo build-docker-image $TARGET`
- #730 - make FreeBSD builds more resilient.
- #670 - Use serde for deserialization of Cross.toml
- Change rust edition to 2021 and bump MSRV for the cross binary to 1.58.1
- #654 - Use color-eyre for error reporting
- #658 - Upgrade dependencies
- #652 - Allow trying individual targets via bors.
Expand Down

0 comments on commit a9223a8

Please sign in to comment.