From a6a012ddae6e5b4768c341e82db9de52a3b5af66 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Fri, 12 May 2023 14:09:18 -0400 Subject: [PATCH] Rework the repo to build edk2 release tags The builder this repo used to pull from has been turned off. It would be nice to have up-to-date edk2 release builds for use with testing in https://github.com/rust-osdev/uefi-rs, without relying on the vagaries of Linux distro releases. Doing our own builds also allows us to ensure we have exactly the build options we want for use with VM testing. As described in the readme, the intended usage is manually pushing a tag corresponding to a release tag in the edk2 repo. That tag will be built in a container, and the resulting tarball will be pushed as a release in this repo (as long as the release doesn't already exist.) I've intentionally kept the container build very simple and linear to make it clear what options are being set for each edk2 build. That leads to some duplication there, but I think the end result is quite easy to follow. --- .github/workflows/build_tag.yml | 17 + .github/workflows/ci.yml | 16 + .github/workflows/create_release.yml | 16 - .gitignore | 1 + Cargo.lock | 811 ++++++--------------------- Cargo.toml | 8 +- Dockerfile | 72 +++ README.md | 26 +- src/main.rs | 213 ++++--- 9 files changed, 434 insertions(+), 746 deletions(-) create mode 100644 .github/workflows/build_tag.yml create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/create_release.yml create mode 100644 Dockerfile diff --git a/.github/workflows/build_tag.yml b/.github/workflows/build_tag.yml new file mode 100644 index 0000000..f511033 --- /dev/null +++ b/.github/workflows/build_tag.yml @@ -0,0 +1,17 @@ +name: Create Release +on: + push: + tags: + - "*" + +permissions: + contents: write + +jobs: + build_tag: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: cargo run -- --container-cmd=docker --create-release $GITHUB_REF_NAME + env: + GH_TOKEN: ${{ github.token }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1daa60b --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,16 @@ +on: + push: + branches: + - main + pull_request: + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: Swatinem/rust-cache@v2 + - run: cargo check + - run: cargo test + - run: cargo fmt -- --check + - run: cargo clippy -- -D warnings diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml deleted file mode 100644 index 81ac7f1..0000000 --- a/.github/workflows/create_release.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Create Release -on: - push: - branches: - - "main" - schedule: - - cron: '21 4 * * *' # every day at 4:21 - -jobs: - create_release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - run: cargo run - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index ea8c4bf..f1ec55a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target +edk2-*-bin* diff --git a/Cargo.lock b/Cargo.lock index 7085c3c..4e54a50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,812 +1,327 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "base64" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" - -[[package]] -name = "bitflags" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" - -[[package]] -name = "bumpalo" -version = "3.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" - -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - -[[package]] -name = "cc" -version = "1.0.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "chunked_transfer" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" +version = 3 [[package]] -name = "convert_case" -version = "0.4.0" +name = "anstream" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" - -[[package]] -name = "cssparser" -version = "0.27.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "754b69d351cdc2d8ee09ae203db831e005560fc6030da058f86ad60c92a9cb0a" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" dependencies = [ - "cssparser-macros", - "dtoa-short", - "itoa", - "matches", - "phf", - "proc-macro2", - "quote", - "smallvec", - "syn", + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", ] [[package]] -name = "cssparser-macros" -version = "0.6.0" +name = "anstyle" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfae75de57f2b2e85e8768c3ea840fd159c8f33e2b6522c7835b7abac81be16e" -dependencies = [ - "quote", - "syn", -] +checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" [[package]] -name = "derive_more" -version = "0.99.13" +name = "anstyle-parse" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f82b1b72f1263f214c0f823371768776c4f5841b942c9883aa8e5ec584fd0ba6" +checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" dependencies = [ - "convert_case", - "proc-macro2", - "quote", - "syn", + "utf8parse", ] [[package]] -name = "dtoa" -version = "0.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0" - -[[package]] -name = "dtoa-short" -version = "0.3.3" +name = "anstyle-query" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bde03329ae10e79ede66c9ce4dc930aa8599043b0743008548680f25b91502d6" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" dependencies = [ - "dtoa", + "windows-sys", ] [[package]] -name = "ego-tree" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a68a4904193147e0a8dec3314640e6db742afd5f6e634f428a6af230d9b3591" - -[[package]] -name = "form_urlencoded" +name = "anstyle-wincon" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" -dependencies = [ - "matches", - "percent-encoding", -] - -[[package]] -name = "futf" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c9c1ce3fa9336301af935ab852c437817d14cd33690446569392e65170aac3b" -dependencies = [ - "mac", - "new_debug_unreachable", -] - -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - -[[package]] -name = "getopts" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" dependencies = [ - "cfg-if", - "libc", - "wasi", + "anstyle", + "windows-sys", ] [[package]] -name = "html5ever" -version = "0.25.1" +name = "anyhow" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aafcf38a1a36118242d29b92e1b08ef84e67e4a5ed06e0a80be20e6a32bfed6b" -dependencies = [ - "log", - "mac", - "markup5ever", - "proc-macro2", - "quote", - "syn", -] +checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" [[package]] -name = "idna" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - -[[package]] -name = "itoa" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" - -[[package]] -name = "js-sys" -version = "0.3.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d99f9e3e84b8f67f846ef5b4cbbc3b1c29f6c759fcbce6f01aa0e73d932a24c" -dependencies = [ - "wasm-bindgen", -] - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.93" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41" - -[[package]] -name = "log" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "mac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4" - -[[package]] -name = "markup5ever" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aae38d669396ca9b707bfc3db254bc382ddb94f57cc5c235f34623a669a01dab" -dependencies = [ - "log", - "phf", - "phf_codegen", - "serde", - "serde_derive", - "serde_json", - "string_cache", - "string_cache_codegen", - "tendril", -] - -[[package]] -name = "matches" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" - -[[package]] -name = "new_debug_unreachable" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" - -[[package]] -name = "nodrop" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" - -[[package]] -name = "once_cell" -version = "1.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" - -[[package]] -name = "ovmf-prebuilt" -version = "0.1.0" -dependencies = [ - "scraper", - "ureq", -] - -[[package]] -name = "percent-encoding" -version = "2.1.0" +name = "bitflags" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "phf" -version = "0.8.0" +name = "cc" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12" -dependencies = [ - "phf_macros", - "phf_shared", - "proc-macro-hack", -] +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] -name = "phf_codegen" -version = "0.8.0" +name = "clap" +version = "4.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbffee61585b0411840d3ece935cce9cb6321f01c45477d30066498cd5e1a815" +checksum = "34d21f9bf1b425d2968943631ec91202fe5e837264063503708b83013f8fc938" dependencies = [ - "phf_generator", - "phf_shared", + "clap_builder", + "clap_derive", + "once_cell", ] [[package]] -name = "phf_generator" -version = "0.8.0" +name = "clap_builder" +version = "4.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" +checksum = "914c8c79fb560f238ef6429439a30023c862f7a28e688c58f7203f12b29970bd" dependencies = [ - "phf_shared", - "rand", + "anstream", + "anstyle", + "bitflags", + "clap_lex", + "strsim", ] [[package]] -name = "phf_macros" -version = "0.8.0" +name = "clap_derive" +version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f6fde18ff429ffc8fe78e2bf7f8b7a5a5a6e2a8b58bc5a9ac69198bbda9189c" +checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" dependencies = [ - "phf_generator", - "phf_shared", - "proc-macro-hack", + "heck", "proc-macro2", "quote", "syn", ] [[package]] -name = "phf_shared" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7" -dependencies = [ - "siphasher", -] - -[[package]] -name = "ppv-lite86" -version = "0.2.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" - -[[package]] -name = "precomputed-hash" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" - -[[package]] -name = "proc-macro-hack" -version = "0.5.19" +name = "clap_lex" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" +checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" [[package]] -name = "proc-macro2" -version = "1.0.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a152013215dca273577e18d2bf00fa862b89b24169fb78c4c95aeb07992c9cec" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "1.0.9" +name = "colorchoice" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" -dependencies = [ - "proc-macro2", -] +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] -name = "rand" -version = "0.7.3" +name = "errno" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" dependencies = [ - "getrandom", + "errno-dragonfly", "libc", - "rand_chacha", - "rand_core", - "rand_hc", - "rand_pcg", + "windows-sys", ] [[package]] -name = "rand_chacha" -version = "0.2.2" +name = "errno-dragonfly" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom", + "cc", + "libc", ] [[package]] -name = "rand_hc" -version = "0.2.0" +name = "heck" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core", -] +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] -name = "rand_pcg" -version = "0.2.1" +name = "hermit-abi" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" -dependencies = [ - "rand_core", -] +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" [[package]] -name = "ring" -version = "0.16.20" +name = "io-lifetimes" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" dependencies = [ - "cc", + "hermit-abi", "libc", - "once_cell", - "spin", - "untrusted", - "web-sys", - "winapi", + "windows-sys", ] [[package]] -name = "rustls" -version = "0.19.0" +name = "is-terminal" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "064fd21ff87c6e87ed4506e68beb42459caa4a0e2eb144932e6776768556980b" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ - "base64", - "log", - "ring", - "sct", - "webpki", + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys", ] [[package]] -name = "ryu" -version = "1.0.5" +name = "libc" +version = "0.2.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" [[package]] -name = "scraper" -version = "0.12.0" +name = "linux-raw-sys" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48e02aa790c80c2e494130dec6a522033b6a23603ffc06360e9fe6c611ea2c12" -dependencies = [ - "cssparser", - "ego-tree", - "getopts", - "html5ever", - "matches", - "selectors", - "smallvec", - "tendril", -] +checksum = "ece97ea872ece730aed82664c424eb4c8291e1ff2480247ccf7409044bc6479f" [[package]] -name = "sct" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "selectors" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df320f1889ac4ba6bc0cdc9c9af7af4bd64bb927bccdf32d81140dc1f9be12fe" -dependencies = [ - "bitflags", - "cssparser", - "derive_more", - "fxhash", - "log", - "matches", - "phf", - "phf_codegen", - "precomputed-hash", - "servo_arc", - "smallvec", - "thin-slice", -] - -[[package]] -name = "serde" -version = "1.0.125" +name = "once_cell" +version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] -name = "serde_derive" -version = "1.0.125" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d" +name = "ovmf-prebuilt" +version = "0.1.0" dependencies = [ - "proc-macro2", - "quote", - "syn", + "anyhow", + "clap", ] [[package]] -name = "serde_json" -version = "1.0.64" +name = "proc-macro2" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ - "itoa", - "ryu", - "serde", + "unicode-ident", ] [[package]] -name = "servo_arc" -version = "0.1.1" +name = "quote" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d98238b800e0d1576d8b6e3de32827c2d74bee68bb97748dcf5071fb53965432" +checksum = "8f4f29d145265ec1c483c7c654450edde0bfe043d3938d6972630663356d9500" dependencies = [ - "nodrop", - "stable_deref_trait", + "proc-macro2", ] [[package]] -name = "siphasher" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbce6d4507c7e4a3962091436e56e95290cb71fa302d0d270e32130b75fbff27" - -[[package]] -name = "smallvec" -version = "1.6.1" +name = "rustix" +version = "0.37.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" - -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - -[[package]] -name = "string_cache" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ddb1139b5353f96e429e1a5e19fbaf663bddedaa06d1dbd49f82e352601209a" +checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" dependencies = [ - "lazy_static", - "new_debug_unreachable", - "phf_shared", - "precomputed-hash", - "serde", + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys", ] [[package]] -name = "string_cache_codegen" -version = "0.5.1" +name = "strsim" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f24c8e5e19d22a726626f1a5e16fe15b132dcf21d10177fa5a45ce7962996b97" -dependencies = [ - "phf_generator", - "phf_shared", - "proc-macro2", - "quote", -] +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.69" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fe99c6bd8b1cc636890bcc071842de909d902c81ac7dab53ba33c421ab8ffb" +checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01" dependencies = [ "proc-macro2", "quote", - "unicode-xid", -] - -[[package]] -name = "tendril" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9ef557cb397a4f0a5a3a628f06515f78563f2209e64d47055d9dc6052bf5e33" -dependencies = [ - "futf", - "mac", - "utf-8", -] - -[[package]] -name = "thin-slice" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" - -[[package]] -name = "tinyvec" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b5220f05bb7de7f3f53c7c065e1199b3172696fe2db9f9c4d8ad9b4ee74c342" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" - -[[package]] -name = "unicode-bidi" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eeb8be209bb1c96b7c177c7420d26e04eccacb0eeae6b980e35fcb74678107e0" -dependencies = [ - "matches", + "unicode-ident", ] [[package]] -name = "unicode-normalization" -version = "0.1.17" +name = "unicode-ident" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" -dependencies = [ - "tinyvec", -] +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] -name = "unicode-width" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" - -[[package]] -name = "unicode-xid" +name = "utf8parse" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" - -[[package]] -name = "untrusted" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" [[package]] -name = "ureq" -version = "2.1.0" +name = "windows-sys" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fbeb1aabb07378cf0e084971a74f24241273304653184f54cdce113c0d7df1b" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "base64", - "chunked_transfer", - "log", - "once_cell", - "rustls", - "url", - "webpki", - "webpki-roots", + "windows-targets", ] [[package]] -name = "url" -version = "2.2.1" +name = "windows-targets" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" dependencies = [ - "form_urlencoded", - "idna", - "matches", - "percent-encoding", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] [[package]] -name = "utf-8" -version = "0.7.5" +name = "windows_aarch64_gnullvm" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05e42f7c18b8f902290b009cde6d651262f956c98bc51bca4cd1d511c9cd85c7" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" +name = "windows_aarch64_msvc" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] -name = "wasm-bindgen" -version = "0.2.73" +name = "windows_i686_gnu" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83240549659d187488f91f33c0f8547cbfef0b2088bc470c116d1d260ef623d9" -dependencies = [ - "cfg-if", - "wasm-bindgen-macro", -] +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] -name = "wasm-bindgen-backend" -version = "0.2.73" +name = "windows_i686_msvc" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae70622411ca953215ca6d06d3ebeb1e915f0f6613e3b495122878d7ebec7dae" -dependencies = [ - "bumpalo", - "lazy_static", - "log", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e734d91443f177bfdb41969de821e15c516931c3c3db3d318fa1b68975d0f6f" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d53739ff08c8a68b0fdbcd54c372b8ab800b1449ab3c9d706503bc7dd1621b2c" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-backend", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.73" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9a543ae66aa233d14bb765ed9af4a33e81b8b58d1584cf1b47ff8cd0b9e4489" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] -name = "web-sys" -version = "0.3.50" +name = "windows_x86_64_gnu" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a905d57e488fec8861446d3393670fb50d27a262344013181c2cdf9fff5481be" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "webpki" -version = "0.21.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "webpki-roots" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" -dependencies = [ - "webpki", -] - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" +name = "windows_x86_64_gnullvm" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "windows_x86_64_msvc" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/Cargo.toml b/Cargo.toml index ce0de72..0ce0ef3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,10 +2,8 @@ name = "ovmf-prebuilt" version = "0.1.0" authors = ["Philipp Oppermann "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +edition = "2021" [dependencies] -ureq = "2.1.0" -scraper = "0.12.0" +anyhow = "1.0.71" +clap = { version = "4.2.7", features = ["derive"] } diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3d76157 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,72 @@ +FROM docker.io/debian:bookworm-slim + +RUN apt-get update && apt-get install -y \ + g++ \ + gcc \ + gcc-aarch64-linux-gnu \ + git \ + make \ + mono-complete \ + python3 \ + python3-venv \ + uuid-dev + +# Use git rather than a release tarball, since the tarball is missing +# submodules. +ARG git_tag +RUN git clone --branch "${git_tag}" https://github.com/tianocore/edk2.git +WORKDIR /edk2 +RUN git submodule update --init + +# Set up deps. +RUN python3 -m venv venv +RUN . venv/bin/activate && pip install -r pip-requirements.txt --upgrade +ENV toolchain=GCC5 +RUN . venv/bin/activate && python BaseTools/Edk2ToolsBuild.py -t "${toolchain}" + +# Build AARCH64. +ENV GCC5_AARCH64_PREFIX="/usr/bin/aarch64-linux-gnu-" +# Note: when updating to the next release, replace PlatformBuild.py with QemuBuild.py +ENV build_target=RELEASE +ENV stuart_opts="-c ArmVirtPkg/PlatformCI/PlatformBuild.py -a AARCH64 Target=${build_target} TOOL_CHAIN_TAG=${toolchain}" +RUN . venv/bin/activate && stuart_setup ${stuart_opts} && stuart_update ${stuart_opts} && stuart_build ${stuart_opts} + +# Build IA32. +ENV stuart_opts="-c OvmfPkg/PlatformCI/PlatformBuild.py -a IA32 Target=${build_target} TOOL_CHAIN_TAG=${toolchain} BLD_*_TPM1_ENABLE=1 BLD_*_TPM2_ENABLE=1" +RUN . venv/bin/activate && stuart_setup ${stuart_opts} && stuart_update ${stuart_opts} && stuart_build ${stuart_opts} + +# Build X64. +ENV stuart_opts="-c OvmfPkg/PlatformCI/PlatformBuild.py -a X64 Target=${build_target} TOOL_CHAIN_TAG=${toolchain} BLD_*_TPM1_ENABLE=1 BLD_*_TPM2_ENABLE=1" +RUN . venv/bin/activate && stuart_setup ${stuart_opts} && stuart_update ${stuart_opts} && stuart_build ${stuart_opts} + +# Create the output bin dir. +ARG bin_dir +RUN mkdir "${bin_dir}" +RUN mkdir "${bin_dir}"/aarch64 +RUN mkdir "${bin_dir}"/ia32 +RUN mkdir "${bin_dir}"/x64 + +# Copy AARCH64 files to bin dir. +ENV aarch64_build="Build/ArmVirtQemu-AARCH64/${build_target}_${toolchain}" +RUN cp "${aarch64_build}/FV/QEMU_EFI.fd" "${bin_dir}"/aarch64/code.fd +RUN cp "${aarch64_build}/FV/QEMU_VARS.fd" "${bin_dir}"/aarch64/vars.fd +RUN cp "${aarch64_build}/AARCH64/Shell.efi" "${bin_dir}"/aarch64/shell.efi +# QEMU requires the AARCH64 files to be exactly 64MiB, so expand with zeroes. +RUN truncate --size=64MiB "${bin_dir}"/aarch64/code.fd +RUN truncate --size=64MiB "${bin_dir}"/aarch64/vars.fd + +# Copy IA32 files to bin dir. +ENV ia32_build="Build/OvmfIa32/${build_target}_${toolchain}" +RUN cp "${ia32_build}/FV/OVMF_CODE.fd" "${bin_dir}"/ia32/code.fd +RUN cp "${ia32_build}/FV/OVMF_VARS.fd" "${bin_dir}"/ia32/vars.fd +RUN cp "${ia32_build}/IA32/Shell.efi" "${bin_dir}"/ia32/shell.efi + +# Copy X64 files to bin dir. +ENV x64_build="Build/OvmfX64/${build_target}_${toolchain}" +RUN cp "${x64_build}/FV/OVMF_CODE.fd" "${bin_dir}"/x64/code.fd +RUN cp "${x64_build}/FV/OVMF_VARS.fd" "${bin_dir}"/x64/vars.fd +RUN cp "${x64_build}/X64/Shell.efi" "${bin_dir}"/x64/shell.efi + +# Create the compressed tarball of the bin dir. +RUN tar cf "${bin_dir}.tar" "${bin_dir}" +RUN xz "${bin_dir}.tar" diff --git a/README.md b/README.md index de63f1a..b1e8799 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,19 @@ # ovmf-prebuilt -Downloads and extracts the prebuilt [OVMF](https://github.com/tianocore/tianocore.github.io/wiki/OVMF) binaries from [Gerd Hoffman's RPM builds](https://www.kraxel.org/repos/) and provides them as GitHub releases. +Builds a release tag of [edk2] and uploads it as a Github release to this repo. + +The contents of the release tarball look like this: +``` +x64/shell.efi +x64/vars.fd +x64/code.fd +ia32/shell.efi +ia32/vars.fd +ia32/code.fd +aarch64/vars.fd +aarch64/code.fd +aarch64/shell.efi +``` [**Latest Release**](https://github.com/rust-osdev/ovmf-prebuilt/releases/latest) @@ -18,3 +31,14 @@ at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. +## Usage + +The build is ordinarily run with Github Actions by manually pushing a tag to the repo. The tag should look something like `edk2-stable202211-r1`. The first part, `edk2-stable202211`, should match a tag in the [edk2] repo. The `-r1` at the end is so that we can do multiple releases of the same edk2 tag without overwriting previous ones (e.g. if we realize later we need to modify a build flag). + +The build can be run locally with: + +``` +cargo run -- [--container-cmd ] [--create-release] +``` + +[edk2]: https://github.com/tianocore/edk2 diff --git a/src/main.rs b/src/main.rs index f086550..5793aa1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,90 +1,151 @@ -use std::path::Path; - -fn main() { - let url = "https://www.kraxel.org/repos/jenkins/edk2/"; - let body = ureq::get(url).call().unwrap().into_string().unwrap(); - let parsed = scraper::Html::parse_document(&body); - let selector = scraper::Selector::parse("a").unwrap(); - - let file_name = parsed - .select(&selector) - .map(|e| e.value().attr("href").unwrap()) - .find(|link| link.contains("git-ovmf-x64")) - .expect("no ovmf link found"); - println!("Downloading {}", file_name); - let (date, build_number, hash) = { - let stripped = file_name.strip_prefix("edk2.git-ovmf-x64-0-").unwrap(); - let mut components = stripped.split('.'); - let date = components.next().unwrap(); - let build_number = components.next().unwrap(); - let hash = components.next().unwrap(); - (date, build_number, hash) - }; - - let target_dir = Path::new("target").join("download"); - std::fs::create_dir_all(&target_dir).unwrap(); - - let mut download = ureq::get(&(url.to_string() + file_name)) - .call() - .unwrap() - .into_reader(); - let target_file_path = target_dir.join(file_name); - let mut target_file = std::fs::File::create(&target_file_path).unwrap(); - std::io::copy(&mut download, &mut target_file).unwrap(); - - let cpio = target_file_path.with_extension("cpio"); - if cpio.exists() { - std::fs::remove_file(&cpio).unwrap(); +use anyhow::{anyhow, bail, Result}; +use clap::Parser; +use std::fs; +use std::path::PathBuf; +use std::process::Command; + +#[derive(Debug, Eq, PartialEq)] +struct Release { + prebuilt_git_tag: String, + edk2_git_tag: String, + release_number: u32, +} + +impl Release { + /// The tag should look something like "edk2-stable202211-r1". The + /// first part, "edk2-stable202211", should match a tag in the edk2 + /// repo. The "-r1" at the end is so that we can do multiple releases + /// of the same edk2 tag without overwriting previous ones (e.g. if + /// we realize later we need to modify a build flag). + fn from_tag(tag: &str) -> Result { + let parts: Vec<_> = tag.rsplitn(2, '-').collect(); + let edk2_git_tag = parts[1]; + if !edk2_git_tag.starts_with("edk2-") { + bail!("bad edk2 git tag"); + } + let release_number = parts[0] + .strip_prefix('r') + .ok_or(anyhow!("bad release number"))?; + Ok(Self { + prebuilt_git_tag: tag.to_string(), + edk2_git_tag: edk2_git_tag.to_string(), + release_number: release_number.parse()?, + }) + } + + /// Get the tarball name based off the git tag. + fn tarball_name(&self) -> String { + format!("{}-bin.tar.xz", self.prebuilt_git_tag) + } + + /// Check if this release has already been pushed. + fn exists(&self) -> bool { + let mut cmd = Command::new("gh"); + cmd.arg("release").arg("view").arg(&self.prebuilt_git_tag); + cmd.status().unwrap().success() } - let extracted = target_dir.join("extracted"); - if extracted.exists() { - std::fs::remove_dir_all(&extracted).unwrap(); + + /// Push the tarball as a new release. + fn push(&self) -> Result<()> { + let release_notes = format!( + "edk2 tag: https://github.com/tianocore/edk2/releases/tag/{}", + self.edk2_git_tag + ); + + println!("Creating release {}", self.prebuilt_git_tag); + let mut cmd = Command::new("gh"); + cmd.args(["release", "create", &self.prebuilt_git_tag]) + .args(["--title", &self.prebuilt_git_tag]) + .args(["--notes", &release_notes]) + .arg(self.tarball_name()); + let status = cmd.status()?; + if !status.success() { + bail!("gh release failed") + } + Ok(()) } +} + +fn build_tarball(opt: &Opt, release: &Release) -> Result { + let container_tag = "ovmf_prebuilt"; - let mut extract_rpm = std::process::Command::new("7z"); - extract_rpm.arg("x"); - extract_rpm.arg(target_file_path); - extract_rpm.arg(format!("-o{}", target_dir.display())); - if !extract_rpm.status().unwrap().success() { - panic!("rpm extraction failed"); + // Build everything. + let mut cmd = Command::new(&opt.container_cmd); + cmd.args([ + "build", + "-t", + container_tag, + "--build-arg", + &format!("git_tag={}", release.edk2_git_tag), + "--build-arg", + &format!("bin_dir={}-bin", release.prebuilt_git_tag), + ".", + ]); + println!("run: {cmd:?}"); + let status = cmd.status()?; + if !status.success() { + bail!("command failed: {status:?}"); } - let mut extract_cpio = std::process::Command::new("7z"); - extract_cpio.arg("x"); - extract_cpio.arg(&cpio); - extract_cpio.arg(format!("-o{}", extracted.display())); - if !extract_cpio.status().unwrap().success() { - panic!("cpio extraction failed"); + // Copy out the tarball from the image. + let tarball_name = release.tarball_name(); + let mut cmd = Command::new(&opt.container_cmd); + cmd.args(["run", container_tag, "cat", &tarball_name]); + println!("run: {cmd:?}"); + let output = cmd.output()?; + if !output.status.success() { + bail!("command failed: {:?}", output.status); } + fs::write(&tarball_name, output.stdout)?; - let ovmf_root = extracted - .join("usr") - .join("share") - .join("edk2.git") - .join("ovmf-x64"); - assert!(ovmf_root.exists()); + Ok(tarball_name.into()) +} - if std::env::var("CI").as_deref() == Ok("true") { - let version = format!("v0.{}.{}+{}", date, build_number, hash); +#[derive(Parser)] +struct Opt { + /// Base command used to build a container. + #[arg(long, default_value = "docker")] + container_cmd: String, - let exists = { - let mut cmd = std::process::Command::new("gh"); - cmd.arg("release").arg("view").arg(&version); - cmd.status().unwrap().success() - }; + /// Push a new release to the repo. + #[arg(long)] + create_release: bool, - if exists { - println!("Version {} was already released", version); + /// Git tag to release. + tag: String, +} + +fn main() -> Result<()> { + let opt = Opt::parse(); + + let release = Release::from_tag(&opt.tag)?; + + build_tarball(&opt, &release)?; + + if opt.create_release { + if release.exists() { + println!("Release {} already exists", release.prebuilt_git_tag); } else { - println!("Releasing version {}", version); - let mut cmd = std::process::Command::new("gh"); - cmd.arg("release").arg("create").arg(&version); - for entry in std::fs::read_dir(&ovmf_root).unwrap() { - cmd.arg(entry.unwrap().path()); - } - if !cmd.status().unwrap().success() { - panic!("gh release failed") - } + release.push()?; } } + + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_release_from_tag() { + assert_eq!( + Release::from_tag("edk2-stable202211-r2").unwrap(), + Release { + prebuilt_git_tag: "edk2-stable202211-r2".to_string(), + edk2_git_tag: "edk2-stable202211".to_string(), + release_number: 2, + } + ); + } }