Skip to content
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

Make clean respect githubWorkflowOSes #167

Merged

Conversation

mdedetrich
Copy link
Contributor

@mdedetrich mdedetrich commented Sep 28, 2023

Resolves: #159

This PR makes it so that the clean.yml uses the head value in githubWorkflowOSes allowing the clean step to run in environments that only have windows (typically hosted environments and/or projects that only target windows) by putting windows as the first entry in githubWorkflowOSes.

Thankfully github actions already provides a bash/*nix environment under Windows so only a couple of modifications were needed to make the clean.yml script to run on Windows. Unfortunately testing that this script actually runs on a Windows CI is a difficult because you would not only have to merge this PR first to see if it passes but you would also have to change the target of https://github.com/sbt/sbt-github-actions/blob/main/build.sbt#L24 which is not desirable.

Instead to test that this PR works, I made a completely separate repo at https://github.com/mdedetrich/test-sbt-github-actions and added a commit so we can at least see that the clean.yml is running under Windows.

The result can be seen at https://github.com/mdedetrich/test-sbt-github-actions/actions/runs/6350853600 and as you can see it appears to be working fine however @djspiewak if you have time I would look at the changes, particularly #167 (comment) since you wrote the original clean.yml just to make sure I didn't miss anything.

@mdedetrich mdedetrich marked this pull request as draft September 28, 2023 10:51
@mdedetrich mdedetrich force-pushed the make-clean-respect-githubWorkflowOSes branch 8 times, most recently from 0982965 to 68a9ffa Compare September 28, 2023 12:02
} finally {
src.close()
}
private def generateCleanContents(runsOnOs: String) = {
Copy link
Contributor Author

@mdedetrich mdedetrich Sep 28, 2023

Choose a reason for hiding this comment

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

It can be argued that having one single giant string is easier to work with (due to Scala's string interpolation) rather than splitting it up into multiple variables as its done in this PR however since $ is a reserved character for string interpolation and its very commonly used in github workflow .yml files all of the escaping of $ would be tedious/somewhat confusing so I opted to do it this way.

@mdedetrich mdedetrich force-pushed the make-clean-respect-githubWorkflowOSes branch 2 times, most recently from 409d63a to 6f3db0e Compare September 28, 2023 12:38
| ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; }
|
| # A temporary file which receives HTTP response headers.
| TMPFILE=$(mktemp)
Copy link
Contributor Author

@mdedetrich mdedetrich Sep 28, 2023

Choose a reason for hiding this comment

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

This is another change which is rather than using a hardcoded file location (as was done before) instead we use mktemp which should work properly under Windows.

As a minor bonus mktemp is more secure when it comes to the permissions of the created file.

@mdedetrich
Copy link
Contributor Author

mdedetrich commented Sep 28, 2023

Currently blocked by supplypike/setup-bin#319 This is a red herring

@mdedetrich mdedetrich force-pushed the make-clean-respect-githubWorkflowOSes branch 2 times, most recently from 8feb0ea to d08a3fe Compare September 29, 2023 09:33
@mdedetrich mdedetrich force-pushed the make-clean-respect-githubWorkflowOSes branch from d08a3fe to 25cdd44 Compare September 29, 2023 11:11
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
| steps:
| - name: Delete artifacts
| shell: bash {0}
Copy link
Contributor Author

@mdedetrich mdedetrich Sep 29, 2023

Choose a reason for hiding this comment

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

This is an addition which ensures that the script runs in bash under windows. The {0} part is here because by default github actions uses set -e (causing any fail to immediately kill the whole step) and grep on Windows will return an error status code if it cannot find anything causing the entire script to fail, see https://stackoverflow.com/a/73069669

@mdedetrich mdedetrich marked this pull request as ready for review September 29, 2023 11:25
@mdedetrich
Copy link
Contributor Author

@eed3si9n Do you by any chance have time to look into this?

Copy link
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

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

Thanks!

@mdedetrich
Copy link
Contributor Author

Okay I am going to go ahead and merge this and then cut a release for v0.18.0 just to get any feedback incase there is a regression (not expecting any though).

@mdedetrich mdedetrich merged commit 9f00e91 into sbt:main Oct 12, 2023
@mdedetrich mdedetrich deleted the make-clean-respect-githubWorkflowOSes branch October 12, 2023 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

clean.yml doesn't respect githubWorkflowOSes
2 participants