Skip to content

Commit

Permalink
Merge pull request #130 from chenxiaolong/rust
Browse files Browse the repository at this point in the history
avbroot 2.0: Rewrite in Rust
  • Loading branch information
chenxiaolong authored Sep 1, 2023
2 parents ac80abe + d643b51 commit bbe793b
Show file tree
Hide file tree
Showing 116 changed files with 16,061 additions and 6,418 deletions.
5 changes: 5 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[alias]
xtask = "run --package xtask --"

[env]
CARGO_WORKSPACE_DIR = { value = "", relative = true }
33 changes: 14 additions & 19 deletions .github/actions/preload-img-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,34 @@ runs:
with:
key: ${{ inputs.cache-key-prefix }}${{ inputs.device }}
# Make sure any changes to path are also reflected in ci.yml setup
path: tests/files/${{ inputs.device }}-sparse.tar
path: e2e/files/${{ inputs.device }}-sparse.tar

- if: ${{ steps.cache-img.outputs.cache-hit }}
name: Extracting image from sparse archive
shell: sh
run: |
tar -C tests/files -xf tests/files/${{ inputs.device }}-sparse.tar
- if: ${{ ! steps.cache-img.outputs.cache-hit }}
uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: python3-lz4 python3-protobuf
working-directory: e2e/files
run: tar -xf ${{ inputs.device }}-sparse.tar

- if: ${{ ! steps.cache-img.outputs.cache-hit }}
uses: awalsh128/cache-apt-pkgs-action@v1
- name: Restore e2e executable
if: ${{ ! steps.cache-img.outputs.cache-hit }}
uses: actions/cache/restore@v3
with:
packages: python3-strictyaml
key: e2e-${{ github.sha }}-${{ runner.os }}
fail-on-cache-miss: true
path: |
target/release/e2e
target/release/e2e.exe
- name: Downloading device image for ${{ inputs.device }}
if: ${{ ! steps.cache-img.outputs.cache-hit }}
shell: sh
run: |
./tests/tests.py \
download \
--stripped \
--no-magisk \
--device \
${{ inputs.device }}
working-directory: e2e
run: ../target/release/e2e download --stripped -d ${{ inputs.device }}

- if: ${{ ! steps.cache-img.outputs.cache-hit }}
name: Creating sparse archive from image
shell: sh
working-directory: e2e/files
run: |
cd tests/files
tar --sparse -cf ${{ inputs.device }}-sparse.tar \
${{ inputs.device }}/*.stripped
25 changes: 11 additions & 14 deletions .github/actions/preload-magisk-cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,20 @@ runs:
with:
key: ${{ inputs.cache-key }}
# Make sure any changes to path are also reflected in ci.yml setup
path: tests/files/magisk
path: e2e/files/magisk

- if: ${{ ! steps.cache-magisk.outputs.cache-hit }}
uses: awalsh128/cache-apt-pkgs-action@v1
with:
packages: python3-lz4 python3-protobuf

- if: ${{ ! steps.cache-magisk.outputs.cache-hit }}
uses: awalsh128/cache-apt-pkgs-action@v1
- name: Restore e2e executable
if: ${{ ! steps.cache-magisk.outputs.cache-hit }}
uses: actions/cache/restore@v3
with:
packages: python3-strictyaml
key: e2e-${{ github.sha }}-${{ runner.os }}
fail-on-cache-miss: true
path: |
target/release/e2e
target/release/e2e.exe
- name: Downloading Magisk
if: ${{ ! steps.cache-magisk.outputs.cache-hit }}
shell: sh
run: |
./tests/tests.py \
download \
--magisk \
--no-devices
working-directory: e2e
run: ../target/release/e2e download --magisk
30 changes: 0 additions & 30 deletions .github/actions/preload-tox-cache/action.yml

This file was deleted.

180 changes: 110 additions & 70 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,80 +11,139 @@ concurrency:
cancel-in-progress: true

jobs:
build:
runs-on: ${{ matrix.os }}
env:
CARGO_TERM_COLOR: always
RUSTFLAGS: -C strip=symbols
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
with:
# For git describe
fetch-depth: 0

- name: Get version
id: get_version
shell: bash
run: |
echo -n 'version=' >> "${GITHUB_OUTPUT}"
git describe --always \
| sed -E "s/^v//g;s/([^-]*-g)/r\1/;s/-/./g" \
>> "${GITHUB_OUTPUT}"
- name: Get Rust LLVM target triple
id: get_target
shell: bash
env:
RUSTC_BOOTSTRAP: '1'
run: |
echo -n 'name=' >> "${GITHUB_OUTPUT}"
rustc -Z unstable-options --print target-spec-json \
| jq -r '."llvm-target"' \
>> "${GITHUB_OUTPUT}"
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2

- name: Clippy
run: cargo clippy --release --workspace --features static

- name: Build
run: cargo build --release --workspace --features static

- name: Tests
run: cargo test --release --workspace --features static

- name: Archive documentation
uses: actions/upload-artifact@v3
with:
name: avbroot-${{ steps.get_version.outputs.version }}-${{ steps.get_target.outputs.name }}
path: |
LICENSE
README.md
# This is separate so we can have a flat directory structure.
- name: Archive executable
uses: actions/upload-artifact@v3
with:
name: avbroot-${{ steps.get_version.outputs.version }}-${{ steps.get_target.outputs.name }}
path: |
target/release/avbroot
target/release/avbroot.exe
- name: Cache e2e executable
uses: actions/cache@v3
with:
key: e2e-${{ github.sha }}-${{ runner.os }}
path: |
target/release/e2e
target/release/e2e.exe
setup:
name: Prepare workflow data
runs-on: ubuntu-latest
needs: build
timeout-minutes: 2
outputs:
config-path: ${{ steps.load-config.outputs.config-path }}
device-list: ${{ steps.load-config.outputs.device-list }}
magisk-key: ${{ steps.cache-keys.outputs.magisk-key }}
img-key-prefix: ${{ steps.cache-keys.outputs.img-key-prefix }}
img-hit: ${{ steps.get-img-cache.outputs.cache-matched-key }}
tox-key-prefix: ${{ steps.cache-keys.outputs.tox-key-prefix }}
tox-hit: ${{ steps.get-tox-cache.outputs.cache-matched-key }}
steps:
- uses: actions/checkout@v3
with:
submodules: true

- uses: awalsh128/cache-apt-pkgs-action@v1
- name: Restore e2e executable
uses: actions/cache/restore@v3
with:
packages: python3-strictyaml
key: e2e-${{ github.sha }}-${{ runner.os }}
fail-on-cache-miss: true
path: |
target/release/e2e
target/release/e2e.exe
- name: Loading test config
id: load-config
shell: python
working-directory: e2e
run: |
import json
import os
import sys
sys.path.append(os.environ['GITHUB_WORKSPACE'])
import tests.config
config_data = tests.config.load_config()
devices = [d.data for d in config_data['device']]
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f'config-path={tests.config.CONFIG_PATH}\n')
f.write(f"device-list={json.dumps(devices)}\n")
echo 'config-path=e2e/e2e.toml' >> "${GITHUB_OUTPUT}"
echo -n 'device-list=' >> "${GITHUB_OUTPUT}"
../target/release/e2e list \
| jq -cnR '[inputs | select(length > 0)]' \
>> "${GITHUB_OUTPUT}"
- name: Generating cache keys
id: cache-keys
run: |
{
echo "tox-key-prefix=tox-${{ hashFiles('tox.ini') }}-"; \
echo "img-key-prefix=img-${{ hashFiles(steps.load-config.outputs.config-path) }}-"; \
echo "magisk-key=magisk-${{ hashFiles(steps.load-config.outputs.config-path) }}";
} >> $GITHUB_OUTPUT
- name: Checking for cached tox environments
id: get-tox-cache
uses: actions/cache/restore@v3
with:
key: ${{ steps.cache-keys.outputs.tox-key-prefix }}
lookup-only: true
path: |
.tox/
~/.cache/pip
- name: Checking for cached device images
id: get-img-cache
uses: actions/cache/restore@v3
with:
key: ${{ steps.cache-keys.outputs.img-key-prefix }}
lookup-only: true
path: |
tests/files/${{ fromJSON(steps.load-config.outputs.device-list)[0] }}-sparse.tar
e2e/files/${{ fromJSON(steps.load-config.outputs.device-list)[0] }}-sparse.tar
- name: Checking for cached magisk apk
id: get-magisk-cache
uses: actions/cache/restore@v3
with:
key: ${{ steps.cache-keys.outputs.magisk-key }}
lookup-only: true
path: tests/files/magisk
path: e2e/files/magisk

- name: Preloading Magisk cache
if: ${{ ! steps.get-magisk-cache.outputs.cache-hit }}
Expand All @@ -106,54 +165,31 @@ jobs:
device: ${{ fromJSON(needs.setup.outputs.device-list) }}
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Preloading image cache
uses: ./.github/actions/preload-img-cache
with:
cache-key-prefix: ${{ needs.setup.outputs.img-key-prefix }}
device: ${{ matrix.device }}

preload-tox:
name: Preload tox environments
runs-on: ubuntu-latest
needs: setup
timeout-minutes: 5
# Assume that preloading always succesfully cached all tox environments before.
# If for some reason only some got cached, on the first run, the cache will not be preloaded
# which will result in some being downloaded multiple times when running the tests.
if: ${{ ! needs.setup.outputs.tox-hit }}
strategy:
matrix:
python: [py39, py310, py311]
steps:
- uses: actions/checkout@v3

- name: Preloading tox cache
uses: ./.github/actions/preload-tox-cache
with:
cache-key-prefix: ${{ needs.setup.outputs.tox-key-prefix }}
python-version: ${{ matrix.python }}

- name: Generating tox environment
run: tox -e ${{ matrix.python }} --notest

tests:
name: Run test for ${{ matrix.device }} with ${{ matrix.python }}
name: Run test for ${{ matrix.device }} on ${{ matrix.os }}
runs-on: ubuntu-latest
needs: [setup, preload-img, preload-tox]
needs:
- setup
- preload-img
timeout-minutes: 10
# Continue on skipped but not on failures or cancels
if: ${{ always() && ! failure() && ! cancelled() }}
strategy:
matrix:
device: ${{ fromJSON(needs.setup.outputs.device-list) }}
python: [py39, py310, py311]
os:
- ubuntu-latest
- windows-latest
- macos-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Restoring Magisk cache
uses: ./.github/actions/preload-magisk-cache
Expand All @@ -166,12 +202,16 @@ jobs:
cache-key-prefix: ${{ needs.setup.outputs.img-key-prefix }}
device: ${{ matrix.device }}

- name: Restoring tox cache
uses: ./.github/actions/preload-tox-cache
- name: Restore e2e executable
uses: actions/cache/restore@v3
with:
cache-key-prefix: ${{ needs.setup.outputs.tox-key-prefix }}
python-version: ${{ matrix.python }}
key: e2e-${{ github.sha }}-${{ runner.os }}
fail-on-cache-miss: true
path: |
target/release/e2e
target/release/e2e.exe
# Finally run tests
- name: Run test for ${{ matrix.device }} with ${{ matrix.python }}
run: tox -e ${{ matrix.python }} -- --stripped -d ${{ matrix.device }}
- name: Run test for ${{ matrix.device }}
working-directory: e2e
run: ../target/release/e2e test --stripped -d ${{ matrix.device }}
Loading

0 comments on commit bbe793b

Please sign in to comment.