home-assistant: support lightify component (#379007)
[NixPkgs.git] / pkgs / by-name / rp / rpcs3 / update.sh
blobb53d23f88fceb7445b2beffde948ce6d992b6db2
1 #!/usr/bin/env nix-shell
2 #!nix-shell -i bash --pure --keep GITHUB_TOKEN -p nix gnused jq nix-prefetch-git curl cacert
4 set -eou pipefail
6 ROOT="$(dirname "$(readlink -f "$0")")"
7 if [[ ! "$(basename $ROOT)" == "rpcs3" || ! -f "$ROOT/package.nix" ]]; then
8 echo "ERROR: Not in the rpcs3 folder"
9 exit 1
12 if [[ ! -v GITHUB_TOKEN ]]; then
13 echo "ERROR: \$GITHUB_TOKEN not set"
14 exit 1
17 payload=$(jq -cn --rawfile query /dev/stdin '{"query": $query}' <<EOF | curl -s -H "Authorization: bearer $GITHUB_TOKEN" -d '@-' https://api.github.com/graphql
19 repository(owner: "RPCS3", name: "rpcs3") {
20 branch: ref(qualifiedName: "refs/heads/master") {
21 target {
22 oid
23 ... on Commit {
24 history {
25 totalCount
31 tag: refs(refPrefix: "refs/tags/", first: 1, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) {
32 nodes {
33 name
38 EOF
41 commit_sha=$(jq -r .data.repository.branch.target.oid <<< "$payload")
42 major_ver=$(jq -r .data.repository.tag.nodes[0].name <<< "$payload" | sed 's/^v//g')
43 commit_count=$(jq -r .data.repository.branch.target.history.totalCount <<< "$payload")
44 git_ver="$commit_count-${commit_sha::9}"
45 final_ver="$major_ver-$git_ver"
48 echo "INFO: Latest commit is $commit_sha"
49 echo "INFO: Latest version is $final_ver"
51 nix_hash=$(nix-prefetch-git --quiet --fetch-submodules https://github.com/RPCS3/rpcs3.git "$commit_sha" | jq -r .sha256)
52 nix_hash=$(nix hash to-sri --type sha256 "$nix_hash")
53 echo "INFO: Hash is $nix_hash"
55 sed -i -E \
56 -e "s/rpcs3GitVersion\s*=\s*\"[\.a-z0-9-]+\";$/rpcs3GitVersion = \"${git_ver}\";/g" \
57 -e "s/rpcs3Version\s*=\s*\"[\.a-z0-9-]+\";$/rpcs3Version = \"${final_ver}\";/g" \
58 -e "s/rpcs3Revision\s*=\s*\"[a-z0-9]+\";$/rpcs3Revision = \"${commit_sha}\";/g" \
59 -e "s|rpcs3Hash\s*=\s*\"sha256-.*\";$|rpcs3Hash = \"${nix_hash}\";|g" \
60 "$ROOT/package.nix"