Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ task:

host_info_script: |
uname -a
echo "-----"
# -----
cat /etc/os-release
echo "-----"
cat /proc/cpuinfo
echo "-----"
# -----
df -T
# -----
cat /proc/cpuinfo
install_libvirt_vagrant_script: |
apt-get update
apt-get install -y libvirt-daemon libvirt-daemon-system vagrant vagrant-libvirt
Expand Down Expand Up @@ -118,7 +118,10 @@ task:
# Use --whatprovides since some packages are renamed.
rpm -q --whatprovides $RPMS
# install Go
curl -fsSL "https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz" | tar Cxz /usr/local
PREFIX="https://go.dev/dl/"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have jq as option, we could use the JSON feed; https://go.dev/dl/?mode=json&include=stable

There's probably some docs somewhere about that URL (it looks like include=stable only returns stable versions, and the first entry would have the version at least (but first entry is "source", so we probably need to filter on os/arch).

There's some scripts used for the official Golang image on Docker Hub that may be useful; https://github.com/docker-library/golang/blob/e8e87a35e7de2343770e13ec1b6c62cafb95728d/versions.sh

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[kir@kir-rhat runc]$ PREFIX=https://golang.org/dl/
[kir@kir-rhat runc]$ GO_VERSION=1.20
[kir@kir-rhat runc]$ eval $(curl -fsSL "${PREFIX}?mode=json" | jq -r  --arg Ver "$GO_VERSION" '.[] | select(.version | startswith("go\($Ver)")) | .files[] | select(.os == "linux" and .arch == "amd64" and .kind == "archive") | "filename=\"" + .filename + "\""')
[kir@kir-rhat runc]$ echo $PREFIX$filename
https://golang.org/dl/go1.20.3.linux-amd64.tar.gz
[kir@kir-rhat runc]$ GO_VERSION=1.19
[kir@kir-rhat runc]$ eval $(curl -fsSL "${PREFIX}?mode=json" | jq -r  --arg Ver "$GO_VERSION" '.[] | select(.version | startswith("go\($Ver)")) | .files[] | select(.os == "linux" and .arch == "amd64" and .kind == "archive") | "filename=\"" + .filename + "\""')
[kir@kir-rhat runc]$ echo $PREFIX$filename
https://golang.org/dl/go1.19.8.linux-amd64.tar.gz

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bash and friends version was not that bad though...

-    SUFFIX=$(curl -fsSL "$PREFIX" | grep ' href="/dl/go'$GO_VERSION'.*linux-amd64\.tar\.gz"' | head -1 | sed -e 's#^.* href="/dl/\([^"]*\)".*$#\1#g')
-    curl -fsSL "$PREFIX$SUFFIX" | tar Cxz /usr/local
+    eval $(curl -fsSL "${PREFIX}?mode=json" | jq -r  --arg Ver "$GO_VERSION" '.[] | select(.version | startswith("go\($Ver)")) | .files[] | select(.os == "linux" and .arch == "amd64" and .kind == "archive") | "filename=\"" + .filename + "\""')
+    curl -fsSL "$PREFIX$filename" | tar Cxz /usr/local

but jq is the king as it's much more structured and thus bulletproof.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found the docs! https://pkg.go.dev/golang.org/x/website/internal/dl

Ah! I was looking at the source code (spotted that @tianon added a link in that script). Was even considering if we could contribute a query-argument to filter the results by (major.minor) version. The code looks pretty straightforward, and I can envision such a query-parameter being useful for many purposes (including go-setup-action

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bash and friends version was not that bad though...

Agreed! I was mostly concerned it the HTML output was stable enough, and JSON is more structured / stable in that respect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

. Was even considering if we could contribute a query-argument to filter the results by (major.minor) version. The code looks pretty straightforward, and I can envision such a query-parameter being useful for many purposes (including go-setup-action

Yep, I'd rather use something like wget https://go.dev/dl/?version=1.20&os=linux&arch=amd64&kind=archive and be done with it.

Found a semi-relevant issue: golang/go#34864. Judging by it, it would be quite hard to move forward with a change like that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casually stealing that link and adding to the script so I can find it again later 😂 ❤️

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be quite hard to move forward with a change like that.

Yeah, generally most proposals would end up with "Based on the discussion above, this proposal seems like a likely decline"

But just looking at the code, it feels like adding additional filters wouldn't do much harm (and for sure wouldn't break backward compatibility); https://github.com/golang/website/blob/41e922072f17ab2826d9479338314c025602a3a1/internal/dl/server.go#L173-L183

# Find out the latest minor release URL.
eval $(curl -fsSL "${PREFIX}?mode=json" | jq -r --arg Ver "$GO_VERSION" '.[] | select(.version | startswith("go\($Ver)")) | .files[] | select(.os == "linux" and .arch == "amd64" and .kind == "archive") | "filename=\"" + .filename + "\""')
curl -fsSL "$PREFIX$filename" | tar Cxz /usr/local
# install bats
cd /tmp
git clone https://github.com/bats-core/bats-core
Expand Down Expand Up @@ -146,14 +149,16 @@ task:
systemctl restart sshd
host_info_script: |
uname -a
echo "-----"
# -----
/usr/local/go/bin/go version
# -----
systemctl --version
# -----
cat /etc/os-release
echo "-----"
cat /proc/cpuinfo
echo "-----"
# -----
df -T
echo "-----"
systemctl --version
# -----
cat /proc/cpuinfo
check_config_script: |
/home/runc/script/check-config.sh
unit_tests_script: |
Expand Down