From b25bf0242b1538b7ea1921e6724e0acf3d8d20db Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 30 Jun 2023 02:11:49 +0000 Subject: [PATCH] Publish from #817 --- .github/workflows/stable-bob-nvim.yml | 486 ++++++++++++++++++++++++++ Cross.toml | 83 +++++ crates/bob-nvim.toml | 5 + scripts/collect.py | 61 ++++ scripts/info.py | 85 +++++ scripts/misc.py | 55 +++ 6 files changed, 775 insertions(+) create mode 100644 .github/workflows/stable-bob-nvim.yml create mode 100644 Cross.toml create mode 100644 crates/bob-nvim.toml create mode 100644 scripts/collect.py create mode 100644 scripts/info.py create mode 100644 scripts/misc.py diff --git a/.github/workflows/stable-bob-nvim.yml b/.github/workflows/stable-bob-nvim.yml new file mode 100644 index 00000000..b23b39a5 --- /dev/null +++ b/.github/workflows/stable-bob-nvim.yml @@ -0,0 +1,486 @@ +name: bob-nvim stable build + +on: + push: + branches: [ trigger/stable ] + workflow_dispatch: + +env: + index: https://github.com/cargo-prebuilt/index/releases/download/stable-index/ + crate: bob-nvim + version: 2.4.1 + license: MIT + description: '{"description": "A version manager for neovim"}' + dl: https://static.crates.io/crates/bob-nvim/bob-nvim-2.4.1.crate + checksum: a393ea56e33602514ead0f2835d04c8b0a5641eb208e5feff338e13b295e6282 + git: https://github.com/MordechaiHadad/bob + bins: bob + file: ./crates/bob-nvim.toml + CARGO_TERM_COLOR: always + +jobs: + setup: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: DBG - API + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /rate_limit + - name: Cache + uses: actions/cache@v3 + id: cache + with: + path: | + bundle + build + key: ${{ env.crate }}-${{ env.version }}-stable-deps + enableCrossOsArchive: true + - name: Create Folders + if: ${{ !steps.cache.outputs.cache-hit }} + run: | + mkdir -p ~/.cargo/registry/index + mkdir -p ~/.cargo/registry/cache + mkdir -p ~/.cargo/git/db + mkdir -p ./bundle + mkdir -p ./build + - name: Download crate and check hash + if: ${{ !steps.cache.outputs.cache-hit }} + run: | + wget ${{ env.dl }} + echo "${{ env.checksum }} ${{ env.crate }}-${{ env.version }}.crate" | sha256sum -c + tar -xf ${{ env.crate }}-${{ env.version }}.crate + mv ${{ env.crate }}-${{ env.version }}/* ./build + - name: Update Rust + if: ${{ !steps.cache.outputs.cache-hit }} + run: rustup update + - name: Rust Version + if: ${{ !steps.cache.outputs.cache-hit }} + run: rustc --version + - name: Generated lockfile if needed + if: ${{ !steps.cache.outputs.cache-hit }} + working-directory: ./build + run: test -f Cargo.lock || cargo +stable generate-lockfile --verbose + - name: Download Deps + if: ${{ !steps.cache.outputs.cache-hit }} + working-directory: ./build + run: cargo +stable fetch --verbose --locked + - name: Bundle Deps + if: ${{ !steps.cache.outputs.cache-hit }} + run: | + mkdir -p ./bundle/registry + mkdir -p ./bundle/git + cp -r ~/.cargo/registry/index ./bundle/registry + cp -r ~/.cargo/registry/cache ./bundle/registry + cp -r ~/.cargo/git/db ./bundle/git + + reports: + runs-on: ubuntu-latest + needs: [ setup ] + steps: + - uses: actions/checkout@v3 + - name: Get deps and crates from cache + uses: actions/cache@v3 + with: + path: | + bundle + build + key: ${{ env.crate }}-${{ env.version }}-stable-deps + enableCrossOsArchive: true + fail-on-cache-miss: true + - name: Move deps + run: mv ./bundle/* ~/.cargo + - name: Cache Advisory DB + uses: actions/cache@v3 + with: + path: | + ~/.cargo/advisory-db + key: stable-advisory-db + - name: Update Rust + run: rustup update + - name: Rust Version + run: rustc --version + - uses: cargo-prebuilt/cargo-prebuilt-action@v1 + with: + tools: cargo-audit + - name: Generate license report + working-directory: ./build + run: | + echo "Generated on: $(date --utc)" > ../license.report && echo "Crates.io license metadata: ${{ env.license }}" >> ../license.report + echo "Found license texts:" >> ../license.report + tail -n +1 *LICENSE* >> ../license.report || true + tail -n +1 *license* >> ../license.report || true + tail -n +1 *License* >> ../license.report || true + - name: Generate deps report + working-directory: ./build + run: | + echo "Generated on: $(date --utc)" > ../deps.report && cargo +stable tree --verbose --locked -e normal,build >> ../deps.report + - name: Generate audit report + working-directory: ./build + run: | + echo "Generated on: $(date --utc)" > ../audit.report && cargo audit >> ../audit.report || true + - name: Output reports + run: | + echo "### License:" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + cat license.report >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + echo "### Deps:" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + cat deps.report >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + echo "### Audit:" >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + cat audit.report >> $GITHUB_STEP_SUMMARY + echo "\`\`\`" >> $GITHUB_STEP_SUMMARY + - name: Store reports + uses: actions/upload-artifact@v3 + with: + name: reports + path: "*.report" + + t1-cross: + strategy: + fail-fast: false + matrix: + target: [ x86_64-unknown-linux-gnu, x86_64-unknown-linux-musl, aarch64-unknown-linux-gnu, aarch64-unknown-linux-musl ] + env: + CROSS_CONFIG: ../Cross.toml + runs-on: ubuntu-latest + needs: [ setup ] + steps: + - uses: actions/checkout@v3 + - name: Get deps and crates from cache + uses: actions/cache@v3 + with: + path: | + bundle + build + key: ${{ env.crate }}-${{ env.version }}-stable-deps + enableCrossOsArchive: true + fail-on-cache-miss: true + - name: Move deps + run: mv ./bundle/* ~/.cargo + - uses: actions/cache@v3 + if: ${{ !false }} + with: + path: | + build/target + key: ${{ runner.os }}-${{ env.crate }}-${{ env.version }}-stable-${{ matrix.target }} + - name: Update Rust + run: rustup update + - name: Rust Version + run: rustc --version + - uses: cargo-prebuilt/cargo-prebuilt-action@v1 + with: + tools: cross + - name: Build crate + working-directory: ./build + run: cross +stable build --verbose --release --locked --target ${{ matrix.target }} + - name: Collect + run: python ./scripts/collect.py ${{ matrix.target }} ./build/target/${{ matrix.target }}/release ${{ env.bins }} + - name: Artifact + uses: actions/upload-artifact@v3 + with: + name: target-${{ matrix.target }} + path: | + ${{ matrix.target }}.tar.gz + ${{ matrix.target }}.sha256 + ${{ matrix.target }}.hashes.json + + t1-apple-darwin: + strategy: + fail-fast: false + matrix: + target: [ x86_64-apple-darwin, aarch64-apple-darwin ] + runs-on: macos-latest + needs: [ setup ] + steps: + - uses: actions/checkout@v3 + - name: Get deps and crates from cache + uses: actions/cache@v3 + with: + path: | + bundle + build + key: ${{ env.crate }}-${{ env.version }}-stable-deps + enableCrossOsArchive: true + fail-on-cache-miss: true + - name: Move deps + run: mv ./bundle/* ~/.cargo + - uses: actions/cache@v3 + if: ${{ !false }} + with: + path: | + build/target + key: ${{ runner.os }}-${{ env.crate }}-${{ env.version }}-stable-${{ matrix.target }} + - name: Update Rust + run: rustup update + - name: Rust Version + run: rustc --version + - name: Add Rust target + run: rustup target add ${{ matrix.target }} + - uses: cargo-prebuilt/cargo-prebuilt-action@v1 + with: + tools: cargo-auditable + - name: Build crate + working-directory: ./build + run: cargo +stable auditable build --verbose --release --locked --target ${{ matrix.target }} + - name: Collect + run: python ./scripts/collect.py ${{ matrix.target }} ./build/target/${{ matrix.target }}/release ${{ env.bins }} + - name: Artifact + uses: actions/upload-artifact@v3 + with: + name: target-${{ matrix.target }} + path: | + ${{ matrix.target }}.tar.gz + ${{ matrix.target }}.sha256 + ${{ matrix.target }}.hashes.json + + t2-cross: + if: true + strategy: + fail-fast: false + matrix: + target: [ x86_64-unknown-freebsd,riscv64gc-unknown-linux-gnu,s390x-unknown-linux-gnu,armv7-unknown-linux-gnueabihf,armv7-unknown-linux-musleabihf ] + env: + CROSS_CONFIG: ../Cross.toml + runs-on: ubuntu-latest + needs: [ setup ] + steps: + - uses: actions/checkout@v3 + - name: Get deps and crates from cache + uses: actions/cache@v3 + with: + path: | + bundle + build + key: ${{ env.crate }}-${{ env.version }}-stable-deps + enableCrossOsArchive: true + fail-on-cache-miss: true + - name: Move deps + run: mv ./bundle/* ~/.cargo + - uses: actions/cache@v3 + if: ${{ !false }} + with: + path: | + build/target + key: ${{ runner.os }}-${{ env.crate }}-${{ env.version }}-stable-${{ matrix.target }} + - name: Update Rust + run: rustup update + - name: Rust Version + run: rustc --version + - uses: cargo-prebuilt/cargo-prebuilt-action@v1 + with: + tools: cross + - name: Build crate + working-directory: ./build + run: cross +stable build --verbose --release --locked --target ${{ matrix.target }} + - name: Collect + run: python ./scripts/collect.py ${{ matrix.target }} ./build/target/${{ matrix.target }}/release ${{ env.bins }} + - name: Artifact + uses: actions/upload-artifact@v3 + with: + name: target-${{ matrix.target }} + path: | + ${{ matrix.target }}.tar.gz + ${{ matrix.target }}.sha256 + ${{ matrix.target }}.hashes.json + + t2-pc-windows-msvc: + if: true + strategy: + fail-fast: false + matrix: + target: [ x86_64-pc-windows-msvc,aarch64-pc-windows-msvc ] + runs-on: windows-latest + needs: [ setup ] + steps: + - uses: actions/checkout@v3 + - name: Get deps and crates from cache + uses: actions/cache@v3 + with: + path: | + bundle + build + key: ${{ env.crate }}-${{ env.version }}-stable-deps + enableCrossOsArchive: true + fail-on-cache-miss: true + - name: Move deps + run: mv ./bundle/* ~/.cargo + - uses: actions/cache@v3 + if: ${{ !false }} + with: + path: | + build/target + key: ${{ runner.os }}-${{ env.crate }}-${{ env.version }}-stable-${{ matrix.target }} + - name: Update Rust + run: rustup update + - name: Rust Version + run: rustc --version + - name: Add Rust target + run: rustup target add ${{ matrix.target }} + - uses: cargo-prebuilt/cargo-prebuilt-action@v1 + with: + tools: cargo-auditable + - name: Build crate + working-directory: ./build + run: cargo +stable auditable build --verbose --release --locked --target ${{ matrix.target }} + - name: Collect + run: python ./scripts/collect.py ${{ matrix.target }} ./build/target/${{ matrix.target }}/release ${{ env.bins }} + - name: Artifact + uses: actions/upload-artifact@v3 + with: + name: target-${{ matrix.target }} + path: | + ${{ matrix.target }}.tar.gz + ${{ matrix.target }}.sha256 + ${{ matrix.target }}.hashes.json + + t3-cross: + if: true + strategy: + fail-fast: false + matrix: + target: [ x86_64-unknown-netbsd,x86_64-unknown-illumos,x86_64-sun-solaris,powerpc64-unknown-linux-gnu,powerpc64le-unknown-linux-gnu,mips64-unknown-linux-gnuabi64,mips64-unknown-linux-muslabi64,mips64el-unknown-linux-gnuabi64,mips64el-unknown-linux-muslabi64 ] + env: + CROSS_CONFIG: ../Cross.toml + runs-on: ubuntu-latest + needs: [ setup ] + steps: + - uses: actions/checkout@v3 + - name: Get deps and crates from cache + uses: actions/cache@v3 + with: + path: | + bundle + build + key: ${{ env.crate }}-${{ env.version }}-stable-deps + enableCrossOsArchive: true + fail-on-cache-miss: true + - name: Move deps + run: mv ./bundle/* ~/.cargo + - uses: actions/cache@v3 + if: ${{ !false }} + with: + path: | + build/target + key: ${{ runner.os }}-${{ env.crate }}-${{ env.version }}-stable-${{ matrix.target }} + - name: Update Rust + run: rustup update + - name: Rust Version + run: rustc --version + - uses: cargo-prebuilt/cargo-prebuilt-action@v1 + with: + tools: cross + - name: Build crate + working-directory: ./build + run: cross +stable build --verbose --release --locked --target ${{ matrix.target }} + - name: Collect + run: python ./scripts/collect.py ${{ matrix.target }} ./build/target/${{ matrix.target }}/release ${{ env.bins }} + - name: Artifact + uses: actions/upload-artifact@v3 + with: + name: target-${{ matrix.target }} + path: | + ${{ matrix.target }}.tar.gz + ${{ matrix.target }}.sha256 + ${{ matrix.target }}.hashes.json + + push-index: + if: ${{ always() && !contains(needs.*.result, 'cancelled') && !contains(needs.setup.result, 'failure') && !contains(needs.reports.result, 'failure') && !contains(needs.t1-cross.result, 'failure') && !contains(needs.t1-apple-darwin.result, 'failure') && !contains(needs.t2-cross.result, 'failure') && !contains(needs.t2-pc-windows-msvc.result, 'failure') }} + runs-on: ubuntu-latest + needs: [ setup, reports, t1-cross, t1-apple-darwin, t2-cross, t2-pc-windows-msvc, t3-cross ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.11" + - name: Rust Update + run: rustup update + - name: Get rust version guess + run: | + echo "rustc_version=$(rustc --version)" >> $GITHUB_ENV + - uses: actions/download-artifact@v3 + - name: DBG - List Structure + run: ls -R + - name: Create info.json and hashes.json + run: python ./scripts/info.py '${{ env.file }}' '${{ env.version }}' '${{ env.license }}' '${{ env.description }}' '${{ env.rustc_version }}' + - name: Artifact + if: ${{ !false }} + uses: actions/upload-artifact@v3 + with: + name: final + path: | + info.json + hashes.json + reports/*.report + target-*/*.tar.gz + target-*/*.sha256 + - name: Create and push artifacts to release + uses: ncipollo/release-action@v1 + if: ${{ false }} + with: + tag: ${{ env.crate }}-${{ env.version }} + name: ${{ env.crate }}-${{ env.version }} + allowUpdates: true + prerelease: true + artifacts: "info.json,hashes.json,reports/*.report,target-*/*.tar.gz,target-*/*.sha256" + body: "" + - name: Create index file + if: ${{ false }} + run: echo "${{ env.version }}" > ${{ env.crate }} + - name: Push to index + uses: svenstaro/upload-release-action@2.6.1 + if: ${{ false }} + with: + tag: stable-index + overwrite: true + make_latest: true + file: ${{ env.crate }} + - name: DBG - API + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /rate_limit + + banned-index: + if: ${{ false && always() && !contains(needs.*.result, 'cancelled') && !contains(needs.setup.result, 'failure') && !contains(needs.reports.result, 'failure') && (contains(needs.t1-cross.result, 'failure') || contains(needs.t1-apple-darwin.result, 'failure') || contains(needs.t2-cross.result, 'failure') || contains(needs.t2-pc-windows-msvc.result, 'failure')) }} + runs-on: ubuntu-latest + needs: [ setup, reports, t1-cross, t1-apple-darwin, t2-cross, t2-pc-windows-msvc, t3-cross ] + steps: + - uses: actions/checkout@v3 + - name: Create index file + run: echo "${{ env.version }}" > ${{ env.crate }} + - name: Push to index + uses: svenstaro/upload-release-action@2.6.1 + with: + tag: banned-index + make_latest: false + file: ${{ env.crate }} + - name: DBG - API + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /rate_limit + + track-index: + if: ${{ false && always() && !contains(needs.*.result, 'cancelled') && contains(needs.*.result, 'failure') }} + runs-on: ubuntu-latest + needs: [ setup, reports, t1-cross, t1-apple-darwin, t2-cross, t2-pc-windows-msvc, t3-cross ] + steps: + - uses: actions/checkout@v3 + - name: Create index file + run: echo "${{ env.version }}" > ${{ env.crate }} + - name: Push to index + uses: svenstaro/upload-release-action@2.6.1 + with: + tag: track-index + make_latest: false + file: ${{ env.crate }} + - name: DBG - API + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" /rate_limit diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 00000000..ea51ae97 --- /dev/null +++ b/Cross.toml @@ -0,0 +1,83 @@ +[target.x86_64-unknown-linux-gnu] +image = "ghcr.io/cargo-prebuilt/cross-auditable:x86_64-unknown-linux-gnu" + +[target.x86_64-unknown-linux-musl] +image = "ghcr.io/cargo-prebuilt/cross-auditable:x86_64-unknown-linux-musl" + +[target.aarch64-unknown-linux-gnu] +image = "ghcr.io/cargo-prebuilt/cross-auditable:aarch64-unknown-linux-gnu" + +[target.aarch64-unknown-linux-musl] +image = "ghcr.io/cargo-prebuilt/cross-auditable:aarch64-unknown-linux-musl" + +[target.x86_64-unknown-freebsd] +image = "ghcr.io/cargo-prebuilt/cross-auditable:x86_64-unknown-freebsd" + +[target.x86_64-unknown-netbsd] +image = "ghcr.io/cargo-prebuilt/cross-auditable:x86_64-unknown-netbsd" + +[target.x86_64-unknown-illumos] +image = "ghcr.io/cargo-prebuilt/cross-auditable:x86_64-unknown-illumos" + +[target.x86_64-sun-solaris] +image = "ghcr.io/cargo-prebuilt/cross-auditable:x86_64-sun-solaris" + +[target.riscv64gc-unknown-linux-gnu] +image = "ghcr.io/cargo-prebuilt/cross-auditable:riscv64gc-unknown-linux-gnu" + +[target.powerpc64-unknown-linux-gnu] +image = "ghcr.io/cargo-prebuilt/cross-auditable:powerpc64-unknown-linux-gnu" + +[target.powerpc64le-unknown-linux-gnu] +image = "ghcr.io/cargo-prebuilt/cross-auditable:powerpc64le-unknown-linux-gnu" + +[target.s390x-unknown-linux-gnu] +image = "ghcr.io/cargo-prebuilt/cross-auditable:s390x-unknown-linux-gnu" + +[target.mips64-unknown-linux-gnuabi64] +image = "ghcr.io/cargo-prebuilt/cross-auditable:mips64-unknown-linux-gnuabi64" + +[target.mips64-unknown-linux-muslabi64] +image = "ghcr.io/cargo-prebuilt/cross-auditable:mips64-unknown-linux-muslabi64" + +[target.mips64el-unknown-linux-gnuabi64] +image = "ghcr.io/cargo-prebuilt/cross-auditable:mips64el-unknown-linux-gnuabi64" + +[target.mips64el-unknown-linux-muslabi64] +image = "ghcr.io/cargo-prebuilt/cross-auditable:mips64el-unknown-linux-muslabi64" + +[target.i686-unknown-linux-gnu] +image = "ghcr.io/cargo-prebuilt/cross-auditable:i686-unknown-linux-gnu" + +[target.i686-unknown-linux-musl] +image = "ghcr.io/cargo-prebuilt/cross-auditable:i686-unknown-linux-musl" + +[target.i686-unknown-freebsd] +image = "ghcr.io/cargo-prebuilt/cross-auditable:i686-unknown-freebsd" + +[target.armv7-unknown-linux-gnueabihf] +image = "ghcr.io/cargo-prebuilt/cross-auditable:armv7-unknown-linux-gnueabihf" + +[target.armv7-unknown-linux-musleabihf] +image = "ghcr.io/cargo-prebuilt/cross-auditable:armv7-unknown-linux-musleabihf" + +[target.powerpc-unknown-linux-gnu] +image = "ghcr.io/cargo-prebuilt/cross-auditable:powerpc-unknown-linux-gnu" + +[target.mips-unknown-linux-gnu] +image = "ghcr.io/cargo-prebuilt/cross-auditable:mips-unknown-linux-gnu" + +[target.mips-unknown-linux-musl] +image = "ghcr.io/cargo-prebuilt/cross-auditable:mips-unknown-linux-musl" + +[target.mipsel-unknown-linux-gnu] +image = "ghcr.io/cargo-prebuilt/cross-auditable:mipsel-unknown-linux-gnu" + +[target.mipsel-unknown-linux-musl] +image = "ghcr.io/cargo-prebuilt/cross-auditable:mipsel-unknown-linux-musl" + +[target.x86_64-pc-windows-gnu] +image = "ghcr.io/cargo-prebuilt/cross-auditable:x86_64-pc-windows-gnu" + +[target.i686-pc-windows-gnu] +image = "ghcr.io/cargo-prebuilt/cross-auditable:i686-pc-windows-gnu" diff --git a/crates/bob-nvim.toml b/crates/bob-nvim.toml new file mode 100644 index 00000000..4bec2c09 --- /dev/null +++ b/crates/bob-nvim.toml @@ -0,0 +1,5 @@ +[info] +id = "bob-nvim" +git = "https://github.com/MordechaiHadad/bob" +unsupported = [] +bins = ["bob"] diff --git a/scripts/collect.py b/scripts/collect.py new file mode 100644 index 00000000..20376a83 --- /dev/null +++ b/scripts/collect.py @@ -0,0 +1,61 @@ +import hashlib +import json +import os +import stat +import sys +import tarfile + + +def main(target, build_path, bins): + bins = bins.split(",") + + hash_obj = { + "bins": [], + "archive": [], + } + + ending = "" + if "windows" in target: + ending = ".exe" + + with tarfile.open(target + ".tar.gz", "w:gz") as archive: + for b in bins: + basename = b + ending + path = build_path + "/" + basename + + # Permission Fix + if "windows" not in target: + st = os.stat(path) + os.chmod(path, st.st_mode | stat.S_IEXEC) + + # Hashes + with open(path, "rb") as file: + file = file.read() + h = hashlib.sha256(file).hexdigest() + hash_obj["bins"].append({"bin": basename, "hash": h, "type": "sha256"}) + h = hashlib.sha512(file).hexdigest() + hash_obj["bins"].append({"bin": basename, "hash": h, "type": "sha512"}) + + # Add to archive + archive.add(path, basename) + + with open(target + ".tar.gz", "rb") as file: + file = file.read() + h = hashlib.sha256(file).hexdigest() + hash_obj["archive"].append({"hash": h, "type": "sha256"}) + + # TODO: Remove with 0.6.0 of cargo-prebuilt + with open(target + ".sha256", "w") as tmp_file: + tmp_file.write(h) + # + + h = hashlib.sha512(file).hexdigest() + hash_obj["archive"].append({"hash": h, "type": "sha512"}) + + with open(target + ".hashes.json", "w") as file: + file.write(json.dumps(hash_obj)) + + +if __name__ == "__main__": + argv = sys.argv + main(argv[1], argv[2], argv[3]) diff --git a/scripts/info.py b/scripts/info.py new file mode 100644 index 00000000..f5a8217d --- /dev/null +++ b/scripts/info.py @@ -0,0 +1,85 @@ +import datetime +import glob +import json +import sys +import tomllib +from datetime import datetime +import misc + + +def main(filename, version, license_spdx, description, rustc_version_guess): + with open(filename, "rb") as file: + crate_toml = tomllib.load(file) + + description = json.loads(description)["description"] + features = misc.gen_flags(crate_toml) + + targets = [] + for t in glob.glob("target-*"): + targets.append(t[7:]) + + info = { # info.json + "info_version": "1", + "id": crate_toml["info"]["id"], + "version": version, + "license": license_spdx, + "git": crate_toml["info"]["git"], + "description": description, + "bins": crate_toml["info"]["bins"], + "info": { + "rustc_version_guess": rustc_version_guess[6:], + "index_publish_date": datetime.utcnow().strftime("%Y-%m-%d"), + "features_apple": str(features["apple"][0]), + "features_linux": str(features["linux"][0]), + "features_windows": str(features["windows"][0]), + "no_default_features_apple": str(features["apple"][1]), + "no_default_features_linux": str(features["linux"][1]), + "no_default_features_windows": str(features["windows"][1]), + }, + "archive": { + "compression": "gz", + "ext": "tar.gz" + }, + "files": { + "hash": "hashes.json", + "license": "license.report", + "deps": "deps.report", + "audit": "audit.report", + }, + "targets": targets, + } + + with open("./info.json", "w") as file: + file.write(json.dumps(info)) + + hashes = { # hashes.json + "hashes_version": "1", + "hashes": {} + } + + # Fill hashes + for t in targets: + with open(f"./target-{t}/{t}.hashes.json", "r") as file: + blob = { + "archive": {}, + "bins": {} + } + hash_file = json.loads(file.read()) + + for h in hash_file["archive"]: + blob["archive"][h["type"]] = h["hash"] + + for b in hash_file["bins"]: + if b["bin"] not in blob["bins"]: + blob["bins"][b["bin"]] = {} + blob["bins"][b["bin"]][b["type"]] = b["hash"] + + hashes["hashes"][t] = blob + + with open("./hashes.json", "w") as file: + file.write(json.dumps(hashes)) + + +if __name__ == "__main__": + argv = sys.argv + main(argv[1], argv[2], argv[3], argv[4], argv[5]) diff --git a/scripts/misc.py b/scripts/misc.py new file mode 100644 index 00000000..48971c75 --- /dev/null +++ b/scripts/misc.py @@ -0,0 +1,55 @@ +# Misc code to reduce duplicate blocks + +def gen_flags(crate_toml): + apple_flags = [None, False, ""] # FEATURES(0), NO_DEFAULT_FEATURES(1), EXTRA_FLAGS(2) + linux_flags = [None, False, ""] + windows_flags = [None, False, ""] + + if "target" in crate_toml: + targets = crate_toml["target"] + if "all" in targets: + if "features" in targets["all"]: + f = targets["all"]["features"] + apple_flags[0] = f + linux_flags[0] = f + windows_flags[0] = f + if "no-default-features" in targets["all"]: + f = targets["all"]["no-default-features"] + apple_flags[1] = f + linux_flags[1] = f + windows_flags[1] = f + if "flags" in targets["all"]: + f = targets["all"]["flags"] + apple_flags[2] = f + linux_flags[2] = f + windows_flags[2] = f + + if "apple" in targets: + if "features" in targets["apple"]: + apple_flags[0] = targets["apple"]["features"] + if "no-default-features" in targets["apple"]: + apple_flags[1] = targets["apple"]["no-default-features"] + if "flags" in targets["apple"]: + apple_flags[2] = targets["apple"]["flags"] + + if "linux" in targets: + if "features" in targets["linux"]: + linux_flags[0] = targets["linux"]["features"] + if "no-default-features" in targets["linux"]: + linux_flags[1] = targets["linux"]["no-default-features"] + if "flags" in targets["linux"]: + linux_flags[2] = targets["linux"]["flags"] + + if "windows" in targets: + if "features" in targets["windows"]: + windows_flags[0] = targets["windows"]["features"] + if "no-default-features" in targets["windows"]: + windows_flags[1] = targets["windows"]["no-default-features"] + if "flags" in targets["windows"]: + windows_flags[2] = targets["windows"]["flags"] + + return { + "apple": apple_flags, + "linux": linux_flags, + "windows": windows_flags, + }