Skip to content

action: download latest version of apk#4364

Open
craftyguy wants to merge 1 commit into
systemd:mainfrom
craftyguy:update-apk
Open

action: download latest version of apk#4364
craftyguy wants to merge 1 commit into
systemd:mainfrom
craftyguy:update-apk

Conversation

@craftyguy

Copy link
Copy Markdown
Contributor

This uses the gitlab API to fetch the latest release of apk from the upstream apk-tools repo, instead of hardcoding a version.

Since gitlab API can be flaky, I put it in a retry loop. set -x in a subshell in the loop because you can never have too much info if/when things break. I also made the whole thing non-fatal if it still fails to get apk after retrying, because not all of them need apk (even if it means other later jobs using apk might fail). I added a warning for that situation so hopefully it makes it a bit more obvious why a later job using apk might fail if that was the case.

@martinpitt martinpitt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

Comment thread action.yaml Outdated
This uses the gitlab API to fetch the latest release of apk from the
upstream apk-tools repo, instead of hardcoding a version.

Since gitlab API can be flaky, I put it in a retry loop. set -x in a
subshell in the loop because you can never have too much info if/when
things break. I also made the whole thing non-fatal if it still fails
to get apk after retrying, because not all of them need apk (even if it
means other later jobs using apk might fail). I added a warning for that
situation so hopefully it makes it a bit more obvious why a later job
using apk might fail if that was the case.
Comment thread action.yaml
sudo curl -fsSL --retry 5 --retry-all-errors -o /usr/bin/apk "$APK_TOOLS_API/packages/generic/${APK_VERSION}/x86_64/apk.static"
echo "${APK_SHA256} /usr/bin/apk" | sha256sum --check
sudo chmod +x /usr/bin/apk
) || echo "WARNING: Failed to fetch latest apk!"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I really don't like ignoring errors in workflows and tests, it makes things unpredictable and unnecessarily hard. It hasn't hurt us much before, so the simplest way would be to just keep the previous "must succeed" behaviour. Alternatively, this could introduce an option whether to install apk, and for backwards compatibility it could default to on. Then users can switch it off to skip the step if they don't need apk.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think hardcoding the current version as baseline might be fine.

@behrmann behrmann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @craftyguy!

Comment thread action.yaml
set -ex
APK_TOOLS_API="https://gitlab.alpinelinux.org/api/v4/projects/5"
APK_VERSION=$(curl -fsSL --retry 5 --retry-all-errors "$APK_TOOLS_API/repository/tags?per_page=1" | jq -r '.[0].name')
APK_PKG_ID=$(curl -fsSL --retry 5 --retry-all-errors "$APK_TOOLS_API/packages?package_name=${APK_VERSION}&package_type=generic" | jq '.[] | select(.version == "x86_64") | .id')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While testing this out this returned two lines for me, you probably want to ensure that only the latest pkg ID wins.

Comment thread action.yaml
(
set -ex
APK_TOOLS_API="https://gitlab.alpinelinux.org/api/v4/projects/5"
APK_VERSION=$(curl -fsSL --retry 5 --retry-all-errors "$APK_TOOLS_API/repository/tags?per_page=1" | jq -r '.[0].name')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure what the GitLab API guarantees here, but the endpoint returns also rc releases and in between the v3.0.0 rc releases there was v2.14.10, so I don't assume any sorting.

Maybe something like this will do

Suggested change
APK_VERSION=$(curl -fsSL --retry 5 --retry-all-errors "$APK_TOOLS_API/repository/tags?per_page=1" | jq -r '.[0].name')
APK_VERSION=$(curl -fsSL --retry 5 --retry-all-errors "$APK_TOOLS_API/repository/tags?per_page=1" | jq -r '.[].name' | sort -V | tail -1)

Comment thread action.yaml
sudo curl -fsSL --retry 5 --retry-all-errors -o /usr/bin/apk "$APK_TOOLS_API/packages/generic/${APK_VERSION}/x86_64/apk.static"
echo "${APK_SHA256} /usr/bin/apk" | sha256sum --check
sudo chmod +x /usr/bin/apk
) || echo "WARNING: Failed to fetch latest apk!"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think hardcoding the current version as baseline might be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants