Skip to content

Commit

Permalink
Migrating the measurement and publish workflows to GitHub Actions (#1971
Browse files Browse the repository at this point in the history
)

* Add CI with measurements job

* Fixed fmt

* Removed dependency on the branch name

* code refactored

* Fixed upstream repo url

* Added publish workflow

* Disabled gitlab codecov and contract-sizes

* Enabled codecov in GHA

* Added tokens for codecov

* Fixed token

* Disabled docs push to gh-pages

* Disabled docs push to gh-pages

* Cancel in-progress jobs when new commit is added to PR
  • Loading branch information
smiasojed authored Nov 13, 2023
1 parent 0dad1bc commit c7e1979
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/download-artifact/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ runs:
}
- run: unzip data.zip -d ./${{ inputs.DOWNLOAD_DIR }}
shell: bash
shell: bash
6 changes: 3 additions & 3 deletions .github/rust-info/action.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: 'Rust Info'
description: "Rust and Bash details"
name: Rust Info
description: Rust and Bash details
runs:
using: "composite"
using: composite
steps:
- run: |
rustup show
Expand Down
27 changes: 20 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ env:
# later. For example, `riscv32imc-unknown-none-elf`.
RISCV_TARGET: riscv32i-unknown-none-elf

concurrency:
# Cancel in-progress jobs triggered only on pull_requests
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

### lint

jobs:
Expand Down Expand Up @@ -396,7 +401,7 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: ${{ github.job }}_${{ github.sha }}-doc
name: ${{ github.job }}-data
path: ./crate-docs
retention-days: 7

Expand All @@ -414,7 +419,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 100
fetch-depth: 0

- name: Rust Info
uses: ./.github/rust-info
Expand All @@ -434,30 +439,32 @@ jobs:
# The `cargo-taurpalin` coverage reporting tool seems to have better code instrumentation and thus
# produces better results for Rust codebases in general. However, unlike `grcov` it requires
# running docker with `--security-opt seccomp=unconfined` which is why we use `grcov` instead.
CODECOV_P_TOKEN: ${{ secrets.CODECOV_P_TOKEN }}
CODECOV_L_TOKEN: ${{ secrets.CODECOV_L_TOKEN }}
run: |
# RUSTFLAGS are the cause target cache can't be used here
# FIXME: cust-covfix doesn't support the external target dir
# FIXME: rust-covfix doesn't support the external target dir
# https://github.com/Kogia-sima/rust-covfix/issues/7
unset "CARGO_TARGET_DIR"
cargo clean
# make sure there's no stale coverage artifacts
find . -name "*.profraw" -type f -delete
find . -name "*.gcda" -type f -delete
# FIXME: Access from 2 users, should be solved once ci-image works from a non-root user
git config --global --add safe.directory '*'
# RUSTFLAGS are the cause target cache can't be used here
cargo build --verbose --all-features --workspace
cargo test --verbose --all-features --no-fail-fast --workspace
# coverage with branches
grcov . --binary-path ./target/debug/ --source-dir . --output-type lcov --llvm --branch \
--ignore-not-existing --ignore "/*" --ignore "tests/*" --output-path lcov-w-branch.info
rust-covfix lcov-w-branch.info --output lcov-w-branch-fixed.info
# TODO: Enable when Gitlab CI is disabled
#codecov --token "$CODECOV_P_TOKEN" --file lcov-w-branch-fixed.info --nonZero
codecov --token "$CODECOV_P_TOKEN" --file lcov-w-branch-fixed.info --nonZero
# lines coverage
grcov . --binary-path ./target/debug/ --source-dir . --output-type lcov --llvm \
--ignore-not-existing --ignore "/*" --ignore "tests/*" --output-path lcov-lines.info
rust-covfix lcov-lines.info --output lcov-lines-fixed.info
# TODO: Enable when Gitlab CI is disabled
#codecov --token "$CODECOV_TOKEN" --file lcov-lines-fixed.info --nonZero
codecov --token "$CODECOV_L_TOKEN" --file lcov-lines-fixed.info --nonZero
### examples

Expand Down Expand Up @@ -587,3 +594,9 @@ jobs:
scripts/for_all_contracts_exec.sh --path integration-tests -- cargo doc --manifest-path {} \
--document-private-items --verbose --no-deps
# measurements

measurements:
needs: [examples-docs, examples-contract-build, examples-test]
uses: ./.github/workflows/measurements.yml

76 changes: 76 additions & 0 deletions .github/workflows/measurements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: continuous-intergration/measurements

on:
workflow_call:

env:
CARGO_TARGET_DIR: /ci-cache/${{ github.repository }}/targets/${{ github.ref_name }}/${{ github.job }}

jobs:
contract-sizes:
if: ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
defaults:
run:
shell: bash
container:
image: paritytech/ci-unified:bullseye-1.73.0
strategy:
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1

- name: Cache
uses: Swatinem/rust-cache@v2
with:
cache-directories: ${{ env.CARGO_TARGET_DIR }}

- name: Rust Info
uses: ./.github/rust-info

- name: Measure Contract Sizes
env:
PR_NUMBER: ${{ github.event.number }}
run: |
# Variables
MEASUREMENTS_DIR="${GITHUB_WORKSPACE}/../ink-ci-measurements"
SCRIPTS_DIR="${GITHUB_WORKSPACE}/scripts"
ARTIFACTS_DIR="${GITHUB_WORKSPACE}/artifacts"
PR_CONTRACT_SIZES="${MEASUREMENTS_DIR}/pull_request_contract_sizes"
UPSTREAM_BRANCH="master"
UPSTREAM_CONTRACT_SIZES="${MEASUREMENTS_DIR}/${UPSTREAM_BRANCH}_contract_sizes"
UPSTREAM_REPO="https://github.com/paritytech/ink.git"
UPSTREAM_DIR="${MEASUREMENTS_DIR}/ink-${UPSTREAM_BRANCH}"
CONTRACT_SIZES_DIFF="${MEASUREMENTS_DIR}/contract_sizes_diff.md"
# Measure contract sizes for the current branch
mkdir ${MEASUREMENTS_DIR}
${SCRIPTS_DIR}/for_all_contracts_exec.sh --path integration-tests --quiet -- ${SCRIPTS_DIR}/contract_size.sh {} > ${PR_CONTRACT_SIZES}
sed -ie 's/^integration-tests\///g' ${PR_CONTRACT_SIZES}
# Measure contract sizes for the upstream branch
git clone --verbose --depth 1 --branch ${UPSTREAM_BRANCH} ${UPSTREAM_REPO} ${UPSTREAM_DIR}
pushd ${UPSTREAM_DIR}
${SCRIPTS_DIR}/for_all_contracts_exec.sh --path integration-tests --quiet -- ${SCRIPTS_DIR}/contract_size.sh {} > ${UPSTREAM_CONTRACT_SIZES}
sed -ie 's/^integration-tests\///g' ${UPSTREAM_CONTRACT_SIZES}
popd
# Build the comparison table
${SCRIPTS_DIR}/contract_sizes_diff.sh ${UPSTREAM_CONTRACT_SIZES} ${PR_CONTRACT_SIZES} > ${CONTRACT_SIZES_DIFF}
cat ${CONTRACT_SIZES_DIFF}
# Create job artifact
mkdir ${ARTIFACTS_DIR}
mv ${CONTRACT_SIZES_DIFF} ${ARTIFACTS_DIR}/
CARGO_CONTRACT_VERSION=$(cargo-contract --version | egrep --only-matching "cargo-contract.* .*-x86" | sed -s 's/-x86//')
echo "CARGO_CONTRACT_VERSION=\"${CARGO_CONTRACT_VERSION}\"" > ${ARTIFACTS_DIR}/context.out
echo "PR_NUMBER=\"${PR_NUMBER}\"" >> ${ARTIFACTS_DIR}/context.out
rm -rf ${MEASUREMENTS_DIR}
- uses: actions/upload-artifact@v3
with:
name: ${{ github.job }}-data
path: ./artifacts
retention-days: 1
62 changes: 62 additions & 0 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: continuous-intergration/publish-docs

on:
workflow_run:
workflows:
- continuous-integration
types:
- completed

jobs:
publish-docs:
if: >
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_branch == 'master' &&
github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
strategy:
fail-fast: false
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 100

- name: Download Contract Sizes
uses: ./.github/download-artifact
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ARTIFACT_NAME: docs-data
DOWNLOAD_DIR: crate-docs

- name: Push docs
run: |
# Set git config
git config user.email "[email protected]"
git config user.name "paritytech-ci"
git fetch origin gh-pages
# saving README and docs
cp -r ./crate-docs/ /tmp/doc/
cp ./README.md /tmp/doc/
cp -r ./.images/ /tmp/doc/
git checkout gh-pages
mv _config.yml /tmp/doc/
# remove everything and restore generated docs, README and Jekyll config
rm -rf ./*
rm -rf ./.images
mv /tmp/doc/* .
mv /tmp/doc/.images .
# Upload files
git add --all --force
git status
# `git commit` has an exit code of > 0 if there is nothing to commit.
# This unfortunately causes Github to exit immediately and mark this
# job as failed subsequently.
# We don't want to mark the entire job as failed if there's nothing to
# publish though, hence the `|| true`.
git commit -m "Updated docs for ${{ github.event.workflow_run.head_branch }}} and pushed to gh-pages" || true
# TODO: Publish disabled, It will be enabled in last migration step
# git push origin gh-pages --force
rm -rf .git/ ./*
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ docs:
- chown -R nonroot:nonroot ./crate-docs


codecov:
.codecov:
stage: workspace
<<: *docker-env
<<: *test-refs
Expand Down Expand Up @@ -415,7 +415,7 @@ examples-docs:

#### stage: measurements

contract-sizes:
.contract-sizes:
stage: measurements
<<: *docker-env
rules:
Expand Down

0 comments on commit c7e1979

Please sign in to comment.