androidenv: mkrepo/fetchrepo: output update script commit object

This commit is contained in:
Morgan Jones
2025-03-29 22:13:03 +05:30
committed by Masum Reza
parent fb25c379f4
commit 8e4f036bb9
3 changed files with 80 additions and 8 deletions
@@ -8,7 +8,7 @@ die() {
fetch() {
local url="https://dl.google.com/android/repository/$1"
echo "$url -> $2"
echo "$url -> $2" >&2
curl -s "$url" -o "$2" || die "Failed to fetch $url"
}
+76 -5
View File
@@ -4,6 +4,8 @@ require 'json'
require 'rubygems'
require 'nokogiri'
require 'slop'
require 'shellwords'
require 'erb'
# Returns a repo URL for a given package name.
def repo_url value
@@ -487,17 +489,21 @@ end
two_years_ago = today - 2 * 365
input = {}
prev_latest = {}
begin
input_json = (STDIN.tty?) ? "{}" : $stdin.read
input_json = (STDIN.tty?) ? "{}" : STDIN.read
if input_json != nil && !input_json.empty?
input = expire_records(JSON.parse(input_json), two_years_ago)
input = expire_records(JSON.parse(input_json), two_years_ago)
# Just create a new set of latest packages.
prev_latest = input['latest'] || {}
input['latest'] = {}
end
rescue JSON::ParserError => e
$stderr.write(e.message)
STDERR.write(e.message)
return
end
fixup_result = fixup(result)
# Regular installation of Android SDK would keep the previously installed packages even if they are not
@@ -505,4 +511,69 @@ fixup_result = fixup(result)
# therefore the old packages will work as long as the links are working on the Google servers.
output = merge input, fixup_result
puts JSON.pretty_generate(sort_recursively(output))
# See if there are any changes in the latest versions.
cur_latest = output['latest'] || {}
old_versions = []
new_versions = []
changes = []
changed = false
cur_latest.each do |k, v|
prev = prev_latest[k]
if prev && prev != v
old_versions << "#{k}:#{prev}"
new_versions << "#{k}:#{v}"
changes << "#{k}: #{prev} -> #{v}"
changed = true
end
end
# Output metadata for the nixpkgs update script.
changed_paths = []
if changed
if ENV['UPDATE_NIX_ATTR_PATH']
# Instantiate it.
test_result = `nix-shell ../../../../default.nix -A #{Shellwords.join [ENV['UPDATE_NIX_ATTR_PATH']]} 2>&1`
test_status = $?.exitstatus
tests_ran = true
else
tests_ran = false
end
template = ERB.new(<<-EOF, trim_mode: '<>-')
androidenv: <%= changes.join('; ') %>
Performed the following automatic androidenv updates:
<% changes.each do |change| %>
- <%= change -%>
<% end %>
<% if tests_ran %>
Tests exited with status: <%= test_status -%>
<% if test_status != 0 %>
```
<%= test_result -%>
```
<% end %>
<% end %>
EOF
changed_paths << {
attrPath: 'androidenv.androidPkgs.androidsdk',
oldVersion: old_versions.join('; '),
newVersion: new_versions.join('; '),
files: [
File.realpath('repo.json')
],
commitMessage: template.result(binding)
}
end
# nix-update info is on stderr
STDERR.puts JSON.pretty_generate(changed_paths)
# repo is on stdout
STDOUT.puts JSON.pretty_generate(sort_recursively(output))
+3 -2
View File
@@ -6,7 +6,8 @@ set -e
pushd "$(dirname "$0")" &>/dev/null || exit 1
echo "Writing repo.json" >&2
cat ./repo.json | ruby mkrepo.rb \
pid=$BASHPID
ruby mkrepo.rb \
--packages ./xml/repository2-3.xml \
--images ./xml/android-sys-img2-3.xml \
--images ./xml/android-tv-sys-img2-3.xml \
@@ -15,7 +16,7 @@ cat ./repo.json | ruby mkrepo.rb \
--images ./xml/android-automotive-sys-img2-3.xml \
--images ./xml/google_apis-sys-img2-3.xml \
--images ./xml/google_apis_playstore-sys-img2-3.xml \
--addons ./xml/addon2-3.xml \
--addons ./xml/addon2-3.xml <./repo.json 2>/proc/$pid/fd/1 \
| sponge repo.json
popd &>/dev/null