-
Notifications
You must be signed in to change notification settings - Fork 3
Allow disabling cache, some refinements to version selection #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Gregorio Litenstein <g.litenstein@gmail.com>
Signed-off-by: Gregorio Litenstein <g.litenstein@gmail.com>
It’s a useless test. Signed-off-by: Gregorio Litenstein <g.litenstein@gmail.com>
5bf86f3
to
1e4b1f1
Compare
It looks great, thanks! I'll review that today. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HI @Lord-Kamina thank you for your interest in setup-macports and sharing your code to make it better and more useful!
I recommended to make a couple of changes to make the code easier to maintain and more robust, tell me what you think about it.
It was quite a long time, If your interest moved to some other questions I could also do these changes by myself. Thanks!
PS Please also consider describing the changes to the version behavior to the README. Pinning the version explicitly should be the recommended approach but mentioning the ability to track LATEST could be useful.
Maybe warning the users they are using an obsolete version of macports could be useful too?
# - name: 'Determine latest MacPorts Version' | ||
# id: latest-version | ||
# run: | | ||
# macports_release_url=$(curl https://raw.githubusercontent.com/macports/macports-base/master/config/RELEASE_URL || curl https://trac.macports.org/export/HEAD/macports-base/config/RELEASE_URL || curl https://distfiles.macports.org/MacPorts/RELEASE_URL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather define two functions:
macports_release_url()
{
curl https://raw.githubusercontent.com/macports/macports-base/master/config/RELEASE_URL\
|| curl https://trac.macports.org/export/HEAD/macports-base/config/RELEASE_URL\
|| curl https://distfiles.macports.org/MacPorts/RELEASE_URL
}
output_latest_version()
{
awk -F'/v' '{ printf("latest_version=%s\n", $NF) }'
}
macports_release_url | output_latest_version >> ${GITHUB_OUTPUT}
Advantages: less expansions and variables, functions are easy to test/mock.
Common recommendation is to avoid ECHO with variables text, it's super brittle. Generally use printf(1)
instead but if another tool like awk is used, why not print within awk.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered moving his check to a separated workflow that runs periodically (daily?) and opens an issue if a new version is out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pinning the version explicitly should be the recommended approach
I strongly disagree with this, considering it's exceedinly rare for macports updates to have breaking changes.
run: | | ||
${{ github.action_path }}/configure_macports "${{ inputs.parameters }}" | ||
- name: 'Cache MacPorts Installation' | ||
if: ${{ inputs.enable-cache == 'true' || ( inputs.enable-cache == true && inputs.enable-cache != 'false' ) }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems rather convoluted. What is the reason for this? Why not just ${{ inputs.enable-cache }}
since the value is a boolean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I think that boolean inputs are actually parsed as string, instead of real booleans.
@@ -0,0 +1,8 @@ | |||
export selfupdate_macports="false" | |||
export macports_version="$1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export
adds variables to a list that is transmitted to subprocesses, it's useful to pass parameters to subprocesses but I do not think this is your intent here.
export selfupdate_macports="false" | ||
export macports_version="$1" | ||
|
||
if [ "$1" = "" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The empty string does not really convey the idea that we are going to use the latest available version. What about using the string LATEST
instead ?
needs: 'run-testsuite' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: 'Get version From parameters file' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not need to do that here. Add the version selection logic to the action itself and add the detail you're interested in (macports_version) to the action output. It will simplify your design.
fi | ||
macports_version=$(yq ".version // \"${macports_version}\"" < "${parameterfile}") | ||
macports_prefix=$(yq ".prefix // \"${macports_prefix}\"" < "${parameterfile}") | ||
. "${subrdir}/check_version.sh" "${macports_version}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sourcing files that have an effect beyond defining yields very confusing programs. I would recommend to move your logic to the configure_macports
file and add the configuration details to the output of the action. For the logic maybe
leave if the if [ -f "${parameterfile}" ]
untouched and add another block
if [ "${macports_version}" = 'LATEST' ]; then
macports_version="$(determine_latest_macports_version)"
fi
where you define the determine_latest_macports_version
with your curl/awk combo.
if [ "$1" = "" ]; then | ||
macports_release_url=$(curl https://raw.githubusercontent.com/macports/macports-base/master/config/RELEASE_URL || curl https://trac.macports.org/export/HEAD/macports-base/config/RELEASE_URL || curl https://distfiles.macports.org/MacPorts/RELEASE_URL) | ||
export macports_version="$(echo $macports_release_url | awk -F'/v' '{ print $NF }')" | ||
export selfupdate_macports="true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attention to the intent conveyed by quotes. Double quotes are for interpolation and single quotes for literal expressions. It's a bit weird to write "true"
rather than true
here.
;; | ||
esac | ||
known_macos_db | awk -F'-' "-vmacos=${macos}" "-vversion=${version}" ' | ||
. "${subrdir}/check_version.sh" "${version}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather approach this by moving the logic provided by check_version.sh to this file, be sure to define functions printing the desired values instead of storing the values in variables. Continue to use macports.sh everywhere you need your functions.
This PR does a couple things.
It adds an input to allow disabling the cache step. The reason for this is because I intend to wrap this action with something I'm working on, and I'll implement the caching in there.
It removes the "version" parameter from the CI workflows, which is related to
The action gets the version information exclusively from the parameter file. But, if that is left blank, it instead defaults to the latest macports release. If a version is specified, much like using a different prefix, macports will be built from source instead of using an installer package. The reason for this is simple: The package runs selfupdate as a postflight script. If somebody goes to the trouble of specifying a particular version, I assume it's because for some reason they don't want the latest version and thus presumably, they wouldn't want it to update automatically. (Don't really know why would someone want that, though)