diff --git a/.github/workflows/stable-bob-nvim.yml b/.github/workflows/stable-bob-nvim.yml new file mode 100644 index 00000000..df41d313 --- /dev/null +++ b/.github/workflows/stable-bob-nvim.yml @@ -0,0 +1,445 @@ +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 + - uses: actions/setup-python@v4 + with: + python-version: "3.11" + - 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 +# REMOVE + - 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 + - uses: actions/setup-python@v4 + with: + python-version: "3.11" + - 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 +# REMOVE + - 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: [ armv7-unknown-linux-gnueabihf,armv7-unknown-linux-musleabihf ] + env: + CROSS_CONFIG: ../Cross.toml + runs-on: ubuntu-latest + needs: [ setup ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.11" + - 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 +# REMOVE + - 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 ] + runs-on: windows-latest + needs: [ setup ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.11" + - 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 +# REMOVE + - 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: false + strategy: + fail-fast: false + matrix: + target: [ err_no_targets ] + env: + CROSS_CONFIG: ../Cross.toml + runs-on: ubuntu-latest + needs: [ setup ] + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.11" + - 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 +# REMOVE + - 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: Sign info.json and hashes.json + run: | + eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + brew install minisign + echo -n "$SIGNING_KEY" | base64 --decode > ~/.minisign_secret.key + minisign -S -s ~/.minisign_secret.key -m info.json + minisign -S -s ~/.minisign_secret.key -m hashes.json + minisign -V -p ./keys/cargo-prebuilt-index.pub -m info.json + minisign -V -p ./keys/cargo-prebuilt-index.pub -m hashes.json + rm -f ~/.minisign_secret.key + env: + SIGNING_KEY: ${{ secrets.MINISIGN_SIGNING_KEY }} + - 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 + with: + tag: ${{ env.crate }}-${{ env.version }} + name: ${{ env.crate }}-${{ env.version }} + allowUpdates: true + prerelease: true + artifacts: "reports/*.report,target-*/*.tar.gz,target-*/*.sha256,*.minisig,hashes.json,info.json" + body: "" + - name: Create index file + run: echo "${{ env.version }}" > ${{ env.crate }} + - name: Push to index + uses: svenstaro/upload-release-action@2.6.1 + 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 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..2e1799cd --- /dev/null +++ b/crates/bob-nvim.toml @@ -0,0 +1,19 @@ +[info] +id = "bob-nvim" +git = "https://github.com/MordechaiHadad/bob" +unsupported = [ + "x86_64-unknown-freebsd", + "riscv64gc-unknown-linux-gnu", + "s390x-unknown-linux-gnu", + "aarch64-pc-windows-msvc", + "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" +] +bins = ["bob"] diff --git a/keys/cargo-prebuilt-index.pub b/keys/cargo-prebuilt-index.pub new file mode 100644 index 00000000..b3bb3eb1 --- /dev/null +++ b/keys/cargo-prebuilt-index.pub @@ -0,0 +1,2 @@ +untrusted comment: minisign public key 51FF575479E09402 +RWQClOB5VFf/UXuhG+697EOSWlSyIPWjyehJpepjgQ7qsLnZxGQzDnqA \ No newline at end of file diff --git a/keys/cargo-prebuilt-index.pub.base64 b/keys/cargo-prebuilt-index.pub.base64 new file mode 100644 index 00000000..55bc7ce9 --- /dev/null +++ b/keys/cargo-prebuilt-index.pub.base64 @@ -0,0 +1 @@ +dW50cnVzdGVkIGNvbW1lbnQ6IG1pbmlzaWduIHB1YmxpYyBrZXkgNTFGRjU3NTQ3OUUwOTQwMgpSV1FDbE9CNVZGZi9VWHVoRys2OTdFT1NXbFN5SVBXanllaEpwZXBqZ1E3cXNMblp4R1F6RG5xQQo= \ No newline at end of file diff --git a/scripts/collect.py b/scripts/collect.py new file mode 100644 index 00000000..2363b751 --- /dev/null +++ b/scripts/collect.py @@ -0,0 +1,69 @@ +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"}) + h = hashlib.sha3_256(file).hexdigest() + hash_obj["bins"].append({"bin": basename, "hash": h, "type": "sha3_256"}) + h = hashlib.sha3_512(file).hexdigest() + hash_obj["bins"].append({"bin": basename, "hash": h, "type": "sha3_512"}) + + # 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"}) + h = hashlib.sha3_256(file).hexdigest() + hash_obj["archive"].append({"hash": h, "type": "sha3_256"}) + h = hashlib.sha3_512(file).hexdigest() + hash_obj["archive"].append({"hash": h, "type": "sha3_512"}) + + 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..0b3cb950 --- /dev/null +++ b/scripts/info.py @@ -0,0 +1,87 @@ +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", + "sig_info": "info.json.minisig", + "sig_hash": "hashes.json.minisig", + }, + "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, + }