| 1 | #!/usr/bin/env bash |
| 2 | # shellcheck disable=SC1091,SC2034,SC2329 |
| 3 | # The test sources a generated PKGBUILD whose makepkg variables are dynamic. |
| 4 | set -euo pipefail |
| 5 | |
| 6 | repo_root="$(cd "$(dirname "$0")/../.." && pwd)" |
| 7 | temp_root="$(mktemp -d)" |
| 8 | trap 'rm -rf "${temp_root}"' EXIT |
| 9 | |
| 10 | assets_dir="${temp_root}/release-assets" |
| 11 | stage_dir="${temp_root}/stage" |
| 12 | mkdir -p "${assets_dir}" "${stage_dir}" |
| 13 | |
| 14 | sha256_file() { |
| 15 | if command -v sha256sum >/dev/null 2>&1; then |
| 16 | sha256sum "$1" | awk '{print $1}' |
| 17 | else |
| 18 | shasum -a 256 "$1" | awk '{print $1}' |
| 19 | fi |
| 20 | } |
| 21 | |
| 22 | for release_arch in x64 arm64; do |
| 23 | archive_root="codewhale-linux-${release_arch}" |
| 24 | mkdir -p "${stage_dir}/${archive_root}" |
| 25 | printf '#!/usr/bin/env sh\necho codewhale-%s\n' "${release_arch}" \ |
| 26 | > "${stage_dir}/${archive_root}/codewhale" |
| 27 | printf '#!/usr/bin/env sh\necho codew-%s\n' "${release_arch}" \ |
| 28 | > "${stage_dir}/${archive_root}/codew" |
| 29 | chmod 0755 \ |
| 30 | "${stage_dir}/${archive_root}/codewhale" \ |
| 31 | "${stage_dir}/${archive_root}/codew" |
| 32 | COPYFILE_DISABLE=1 tar -czf "${assets_dir}/${archive_root}.tar.gz" \ |
| 33 | -C "${stage_dir}" "${archive_root}" |
| 34 | done |
| 35 | |
| 36 | for manifest in codewhale-artifacts-sha256.txt codewhale-bundles-sha256.txt; do |
| 37 | { |
| 38 | printf '%s %s\n' \ |
| 39 | "$(sha256_file "${assets_dir}/codewhale-linux-x64.tar.gz")" \ |
| 40 | 'codewhale-linux-x64.tar.gz' |
| 41 | printf '%s %s\n' \ |
| 42 | "$(sha256_file "${assets_dir}/codewhale-linux-arm64.tar.gz")" \ |
| 43 | 'codewhale-linux-arm64.tar.gz' |
| 44 | } > "${assets_dir}/${manifest}" |
| 45 | done |
| 46 | |
| 47 | first_output="${temp_root}/first" |
| 48 | second_output="${temp_root}/second" |
| 49 | revision_output="${temp_root}/revision" |
| 50 | bash "${repo_root}/packaging/aur/render.sh" "${assets_dir}" "${first_output}" |
| 51 | bash "${repo_root}/packaging/aur/render.sh" "${assets_dir}" "${second_output}" |
| 52 | bash "${repo_root}/packaging/aur/render.sh" "${assets_dir}" "${revision_output}" 2 |
| 53 | cmp "${first_output}/PKGBUILD" "${second_output}/PKGBUILD" |
| 54 | cmp "${first_output}/.SRCINFO" "${second_output}/.SRCINFO" |
| 55 | |
| 56 | workspace_version="$( |
| 57 | grep -E '^version = "' "${repo_root}/Cargo.toml" \ |
| 58 | | head -n 1 \ |
| 59 | | sed -E 's/^version = "([^"]+)".*/\1/' |
| 60 | )" |
| 61 | grep -Fqx "pkgver=${workspace_version}" "${first_output}/PKGBUILD" |
| 62 | grep -Fqx "depends=('glibc' 'gcc-libs' 'dbus')" "${first_output}/PKGBUILD" |
| 63 | for dependency in glibc gcc-libs dbus; do |
| 64 | grep -Fqx $'\tdepends = '"${dependency}" "${first_output}/.SRCINFO" |
| 65 | done |
| 66 | grep -Fqx 'pkgrel=2' "${revision_output}/PKGBUILD" |
| 67 | grep -Fqx $'\tpkgrel = 2' "${revision_output}/.SRCINFO" |
| 68 | grep -Fq "/releases/download/v${workspace_version}/codewhale-linux-x64.tar.gz" \ |
| 69 | "${first_output}/.SRCINFO" |
| 70 | grep -Fq "/releases/download/v${workspace_version}/codewhale-linux-arm64.tar.gz" \ |
| 71 | "${first_output}/.SRCINFO" |
| 72 | if grep -R -Eq 'SKIP|@[A-Z0-9_]+@' "${first_output}"; then |
| 73 | echo "rendered metadata retained a placeholder or SKIP checksum" >&2 |
| 74 | exit 1 |
| 75 | fi |
| 76 | |
| 77 | for arch_case in 'x86_64:x64' 'aarch64:arm64'; do |
| 78 | carch="${arch_case%%:*}" |
| 79 | release_arch="${arch_case#*:}" |
| 80 | package_src="${temp_root}/package-src-${carch}" |
| 81 | package_root="${temp_root}/package-root-${carch}" |
| 82 | mkdir -p "${package_src}" "${package_root}" |
| 83 | tar -xzf "${assets_dir}/codewhale-linux-${release_arch}.tar.gz" -C "${package_src}" |
| 84 | cp "${repo_root}/LICENSE" "${package_src}/LICENSE-${workspace_version}" |
| 85 | ( |
| 86 | source "${first_output}/PKGBUILD" |
| 87 | install() { |
| 88 | local mode="${1#-Dm}" |
| 89 | command mkdir -p "$(dirname "$3")" |
| 90 | command cp "$2" "$3" |
| 91 | command chmod "${mode}" "$3" |
| 92 | } |
| 93 | CARCH="${carch}" |
| 94 | srcdir="${package_src}" |
| 95 | pkgdir="${package_root}" |
| 96 | package |
| 97 | ) |
| 98 | cmp \ |
| 99 | "${stage_dir}/codewhale-linux-${release_arch}/codewhale" \ |
| 100 | "${package_root}/usr/bin/codewhale" |
| 101 | cmp \ |
| 102 | "${stage_dir}/codewhale-linux-${release_arch}/codew" \ |
| 103 | "${package_root}/usr/bin/codew" |
| 104 | test -L "${package_root}/usr/bin/codewhale-tui" |
| 105 | test "$(readlink "${package_root}/usr/bin/codewhale-tui")" = codewhale |
| 106 | cmp "${repo_root}/LICENSE" \ |
| 107 | "${package_root}/usr/share/licenses/codewhale-bin/LICENSE" |
| 108 | done |
| 109 | |
| 110 | printf 'tampered\n' >> "${assets_dir}/codewhale-linux-x64.tar.gz" |
| 111 | if bash "${repo_root}/packaging/aur/render.sh" \ |
| 112 | "${assets_dir}" "${temp_root}/tampered-output" >/dev/null 2>&1; then |
| 113 | echo "renderer accepted a release archive that no longer matched its manifests" >&2 |
| 114 | exit 1 |
| 115 | fi |
| 116 | |
| 117 | echo "AUR render contract passed" |
| 118 |