mirror of
https://github.com/factoriotools/factorio-docker.git
synced 2025-01-12 19:27:11 +01:00
Use new version API to check update (#466)
* Use new version API
Update latest to experimental
* fix by shellcheck
* Revert "Auto Update Factorio to version:"
This reverts commit dfd442dfda
.
* Fix correct exit when online information get fails
This commit is contained in:
parent
dfd442dfda
commit
bd1ba3cf9d
@ -3,6 +3,14 @@
|
|||||||
[中文](./README_zh_CN.md)
|
[中文](./README_zh_CN.md)
|
||||||
|
|
||||||
<!-- start autogeneration tags -->
|
<!-- start autogeneration tags -->
|
||||||
|
* `1`, `1.1`, `1.1.80`, `latest`, `stable`
|
||||||
|
* `1.0`, `1.0.0`
|
||||||
|
* `0.17`, `0.17.79`
|
||||||
|
* `0.16`, `0.16.51`
|
||||||
|
* `0.15`, `0.15.40`
|
||||||
|
* `0.14`, `0.14.23`
|
||||||
|
* `0.13`, `0.13.20`
|
||||||
|
* `0.12`, `0.12.35`
|
||||||
<!-- end autogeneration tags -->
|
<!-- end autogeneration tags -->
|
||||||
|
|
||||||
## Tag descriptions
|
## Tag descriptions
|
||||||
|
@ -0,0 +1,61 @@
|
|||||||
|
{
|
||||||
|
"0.12.35": {
|
||||||
|
"sha256": "ab9cf01a56dde3073aaaa5152c628bbf9a5bb85638b87dc3d7fdb77fb169aedd",
|
||||||
|
"tags": [
|
||||||
|
"0.12.35",
|
||||||
|
"0.12"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"0.13.20": {
|
||||||
|
"sha256": "cbf5481e4b7e0efcc07c7b6a1fc3ff1404ad5597f3c9d37914a52ffb58d7c159",
|
||||||
|
"tags": [
|
||||||
|
"0.13.20",
|
||||||
|
"0.13"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"0.14.23": {
|
||||||
|
"sha256": "96c3e7acd4e0f066a499baba01823cac7c1caf0e50dbddcea5793f57bd60dc8c",
|
||||||
|
"tags": [
|
||||||
|
"0.14.23",
|
||||||
|
"0.14"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"0.15.40": {
|
||||||
|
"sha256": "1041ef61ea4aecd1f425e6030a909f0c349a9c01d1b3324d84a61b1cfef5ba6c",
|
||||||
|
"tags": [
|
||||||
|
"0.15.40",
|
||||||
|
"0.15"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"0.16.51": {
|
||||||
|
"sha256": "6cb09f5ac87f16f8d5b43cef26c0ae26cc46a57a0382e253dfda032dc5bb367f",
|
||||||
|
"tags": [
|
||||||
|
"0.16.51",
|
||||||
|
"0.16"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"0.17.79": {
|
||||||
|
"sha256": "9ace12fa986df028dc1851bf4de2cb038044d743e98823bc1c48ba21aa4d23df",
|
||||||
|
"tags": [
|
||||||
|
"0.17.79",
|
||||||
|
"0.17"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1.0.0": {
|
||||||
|
"sha256": "81d9e1aa94435aeec4131c8869fa6e9331726bea1ea31db750b65ba42dbd1464",
|
||||||
|
"tags": [
|
||||||
|
"1.0.0",
|
||||||
|
"1.0"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1.1.80": {
|
||||||
|
"sha256": "66c89e01160d40d18f199836ca78d4e6292e828d873df528a70233fe40796635",
|
||||||
|
"tags": [
|
||||||
|
"1",
|
||||||
|
"1.1",
|
||||||
|
"latest",
|
||||||
|
"stable",
|
||||||
|
"1.1.80"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
78
update.sh
78
update.sh
@ -1,11 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
SEMVER_REGEX="^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
|
SEMVER_REGEX="^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
|
||||||
|
|
||||||
version=$(curl 'https://www.factorio.com/updater/get-available-versions?apiVersion=2' | jq '.[] | .[] | select(.stable) | .stable' -r)
|
stable_online_version=$(curl 'https://factorio.com/api/latest-releases' | jq '.stable.headless' -r)
|
||||||
sha256=$(curl "https://www.factorio.com/get-download/${version}/headless/linux64" -L | sha256sum | awk '{print $1}')
|
experimental_online_version=$(curl 'https://factorio.com/api/latest-releases' | jq '.experimental.headless' -r)
|
||||||
currentversion=$(jq 'with_entries(select(contains({value:{tags:["stable"]}}))) | keys | .[0]' buildinfo.json -r)
|
stable_sha256=$(curl "https://www.factorio.com/get-download/${stable_online_version}/headless/linux64" -L | sha256sum | awk '{print $1}')
|
||||||
echo "version:$version currentversion:$currentversion"
|
experimental_sha256=$(curl "https://www.factorio.com/get-download/${experimental_online_version}/headless/linux64" -L | sha256sum | awk '{print $1}')
|
||||||
if [[ "$currentversion" == "$version" ]]; then
|
stable_current_version=$(jq 'with_entries(select(contains({value:{tags:["stable"]}}))) | keys | .[0]' buildinfo.json -r)
|
||||||
|
latest_current_version=$(jq 'with_entries(select(contains({value:{tags:["latest"]}}))) | keys | .[0]' buildinfo.json -r)
|
||||||
|
echo "stable_online_version=${stable_online_version} experimental_online_version=${experimental_online_version}"
|
||||||
|
echo "stable_current_version=${stable_current_version} latest_current_version=${latest_current_version}"
|
||||||
|
if [[ -z "${stable_online_version}" ]] || [[ -z "${experimental_online_version}" ]]; then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
if [[ "${stable_current_version}" == "${stable_online_version}" ]] && [[ "${latest_current_version}" == "${experimental_online_version}" ]]; then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -19,39 +27,65 @@ function get-semver(){
|
|||||||
fi
|
fi
|
||||||
case $type in
|
case $type in
|
||||||
major)
|
major)
|
||||||
echo $major
|
echo "$major"
|
||||||
;;
|
;;
|
||||||
minor)
|
minor)
|
||||||
echo $minor
|
echo "$minor"
|
||||||
;;
|
;;
|
||||||
patch)
|
patch)
|
||||||
echo $patch
|
echo "$patch"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
versionMajor=$(get-semver $version major)
|
stableOnlineVersionMajor=$(get-semver "${stable_online_version}" major)
|
||||||
versionMinor=$(get-semver $version minor)
|
stableOnlineVersionMinor=$(get-semver "${stable_online_version}" minor)
|
||||||
currentversionMajor=$(get-semver $currentversion major)
|
experimentalOnlineVersionMajor=$(get-semver "${experimental_online_version}" major)
|
||||||
currentversionMinor=$(get-semver $currentversion minor)
|
experimentalOnlineVersionMinor=$(get-semver "${experimental_online_version}" minor)
|
||||||
|
stableCurrentVersionMajor=$(get-semver "${stable_current_version}" major)
|
||||||
|
stableCurrentVersionMinor=$(get-semver "${stable_current_version}" minor)
|
||||||
|
latestCurrentVersionMajor=$(get-semver "${latest_current_version}" major)
|
||||||
|
latestCurrentVersionMinor=$(get-semver "${latest_current_version}" minor)
|
||||||
|
|
||||||
versionShort=$versionMajor.$versionMinor
|
stableOnlineVersionShort=$stableOnlineVersionMajor.$stableOnlineVersionMinor
|
||||||
currentversionShort=$currentversionMajor.$currentversionMinor
|
experimentalOnlineVersionShort=$experimentalOnlineVersionMajor.$experimentalOnlineVersionMinor
|
||||||
echo "versionShort=$versionShort currentversionShort=$currentversionShort"
|
stableCurrentVersionShort=$stableCurrentVersionMajor.$stableCurrentVersionMinor
|
||||||
|
latestCurrentVersionShort=$latestCurrentVersionMajor.$latestCurrentVersionMinor
|
||||||
|
|
||||||
|
echo "stableOnlineVersionShort=${stableOnlineVersionShort} experimentalOnlineVersionShort=${experimentalOnlineVersionShort}"
|
||||||
|
echo "stableCurrentVersionShort=${stableCurrentVersionShort} latestCurrentVersionShort=${latestCurrentVersionShort}"
|
||||||
|
|
||||||
tmpfile=$(mktemp)
|
tmpfile=$(mktemp)
|
||||||
|
|
||||||
|
# Remove latest tag
|
||||||
cp buildinfo.json "$tmpfile"
|
cp buildinfo.json "$tmpfile"
|
||||||
if [[ $versionShort == $currentversionShort ]]; then
|
jq --arg latest_current_version "$latest_current_version" 'with_entries(if .key == $latest_current_version then .value.tags |= . - ["latest"] else . end)' "$tmpfile" > buildinfo.json
|
||||||
jq --arg currentversion $currentversion --arg version $version --arg sha256 $sha256 'with_entries(if .key == $currentversion then .key |= $version | .value.sha256 |= $sha256 | .value.tags |= . - [$currentversion] + [$version] else . end)' "$tmpfile" > buildinfo.json
|
rm -f -- "$tmpfile"
|
||||||
|
|
||||||
|
# Update tag by stable
|
||||||
|
cp buildinfo.json "$tmpfile"
|
||||||
|
if [[ $stableOnlineVersionShort == "$stableCurrentVersionShort" ]]; then
|
||||||
|
jq --arg stable_current_version "$stable_current_version" --arg stable_online_version "$stable_online_version" --arg sha256 "$stable_sha256" 'with_entries(if .key == $stable_current_version then .key |= $stable_online_version | .value.sha256 |= $sha256 | .value.tags |= . - [$stable_current_version] + [$stable_online_version] else . end)' "$tmpfile" > buildinfo.json
|
||||||
else
|
else
|
||||||
jq --arg currentversion $currentversion --arg version $version --arg sha256 $sha256 --arg versionShort $versionShort --arg versionMajor $versionMajor 'with_entries(if .key == $currentversion then .value.tags |= . - ["latest","stable",$versionMajor] else . end) | to_entries | . + [{ key: $version, value: { sha256: $sha256, tags: ["latest","stable",$versionMajor,$versionShort,$version]}}] | from_entries' "$tmpfile" > buildinfo.json
|
jq --arg stable_current_version "$stable_current_version" --arg stable_online_version "$stable_online_version" --arg sha256 "$stable_sha256" --arg stableOnlineVersionShort "$stableOnlineVersionShort" --arg stableOnlineVersionMajor "$stableOnlineVersionMajor" 'with_entries(if .key == $stable_current_version then .value.tags |= . - ["latest","stable",$stableOnlineVersionMajor] else . end) | to_entries | . + [{ key: $stable_online_version, value: { sha256: $sha256, tags: ["latest","stable",$stableOnlineVersionMajor,$stableOnlineVersionShort,$stable_online_version]}}] | from_entries' "$tmpfile" > buildinfo.json
|
||||||
fi
|
fi
|
||||||
rm -f -- "$tmpfile"
|
rm -f -- "$tmpfile"
|
||||||
|
|
||||||
readme_tags=$(cat buildinfo.json | jq --sort-keys 'keys[]' | tac | (while read line
|
# Update tag by latest
|
||||||
|
cp buildinfo.json "$tmpfile"
|
||||||
|
if [[ $experimental_online_version != "$stable_online_version" ]]; then
|
||||||
|
if [[ $stableOnlineVersionShort == "$experimentalOnlineVersionShort" ]]; then
|
||||||
|
jq --arg experimental_online_version "$experimental_online_version" --arg stable_online_version "$stable_online_version" --arg sha256 "$experimental_sha256" 'with_entries(if .key == $stable_online_version then .value.tags |= . - ["latest"] else . end) | to_entries | . + [{ key: $experimental_online_version, value: { sha256: $sha256, tags: ["latest", $experimental_online_version]}}] | from_entries' "$tmpfile" > buildinfo.json
|
||||||
|
else
|
||||||
|
jq --arg experimental_online_version "$experimental_online_version" --arg stable_online_version "$stable_online_version" --arg sha256 "$experimental_sha256" --arg experimentalOnlineVersionShort "$experimentalOnlineVersionShort" --arg experimentalOnlineVersionMajor "$experimentalOnlineVersionMajor" 'with_entries(if .key == $stable_online_version then .value.tags |= . - ["latest"] else . end) | to_entries | . + [{ key: $experimental_online_version, value: { sha256: $sha256, tags: ["latest",$experimentalOnlineVersionMajor,$experimentalOnlineVersionShort,$experimental_online_version]}}] | from_entries' "$tmpfile" > buildinfo.json
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
rm -f -- "$tmpfile"
|
||||||
|
|
||||||
|
readme_tags=$(jq --sort-keys 'keys[]' buildinfo.json | tac | (while read -r line
|
||||||
do
|
do
|
||||||
tags="$tags\n* "$(cat buildinfo.json | jq --sort-keys ".$line.tags | sort | .[]" | sed 's/"/`/g' | sed ':a; /$/N; s/\n/, /; ta')
|
tags="$tags\n* "$(jq --sort-keys ".$line.tags | sort | .[]" buildinfo.json | sed 's/"/`/g' | sed ':a; /$/N; s/\n/, /; ta')
|
||||||
done && echo $tags"\n"))
|
done && printf "%s\n\n" "$tags"))
|
||||||
|
|
||||||
perl -i -0777 -pe "s/<!-- start autogeneration tags -->.+<!-- end autogeneration tags -->/<!-- start autogeneration tags -->$readme_tags<!-- end autogeneration tags -->/s" README.md
|
perl -i -0777 -pe "s/<!-- start autogeneration tags -->.+<!-- end autogeneration tags -->/<!-- start autogeneration tags -->$readme_tags<!-- end autogeneration tags -->/s" README.md
|
||||||
|
|
||||||
@ -60,7 +94,7 @@ git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
|||||||
|
|
||||||
git add buildinfo.json
|
git add buildinfo.json
|
||||||
git add README.md
|
git add README.md
|
||||||
git commit -a -m "Auto Update Factorio to version: $version"
|
git commit -a -m "Auto Update Factorio to stable version: ${stable_online_version} experimental version: ${experimental_online_version}"
|
||||||
|
|
||||||
git tag -f latest
|
git tag -f latest
|
||||||
git push
|
git push
|
||||||
|
Loading…
Reference in New Issue
Block a user