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

#104 Run tests for the user creating the PR #106

Closed
wants to merge 1 commit into from

Conversation

filiphr
Copy link
Contributor

@filiphr filiphr commented Jan 4, 2024

Adding a step in the GitHub action to test the submission of the user submitting the PR

Fixes #104

@gunnarmorling please wait for merging, I want to also push some failures to see how it looks like.

cc @AlexanderYastrebov

@filiphr
Copy link
Contributor Author

filiphr commented Jan 4, 2024

A failure would look like

image

and then if you go into details you'll see

image

@filiphr
Copy link
Contributor Author

filiphr commented Jan 4, 2024

I've also added a check to validate that the file exists. If a file does not exists it will have an error like

image

@filiphr
Copy link
Contributor Author

filiphr commented Jan 4, 2024

@gunnarmorling this is now ready for merging. I've removed the commits that were causing failures.

echo "$CALCULATE_FILE does not exist."
exit 1
fi

for sample in $(ls src/test/resources/samples/*.txt); do
echo "Validating calculate_average_$1.sh -- $sample"
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess we can change this to echo "Validating $1 -- $sample" to make it a bit cleaner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds OK to me. I'll change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to change this. I think we can merge without it, and we can change it later.

@@ -47,3 +47,7 @@ jobs:

- name: 'Build project'
run: mvn -B clean verify -Pci

- name: 'Test submission'
run: ./test.sh ${{ github.event.pull_request.user.login }}
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure this will work for all submissions, e.g. some use sdk or graal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed it might not work. I'll see if we can use https://github.com/sdkman/sdkman-action/tree/main

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, I think this would be good. Wanna add it to this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Was already working on it, but I am travelling today so a bit slow :)

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a related ticket #150

@AlexanderYastrebov
Copy link
Contributor

I thin PR description fixes wrong ticket, should be #104

@filiphr
Copy link
Contributor Author

filiphr commented Jan 4, 2024

I thin PR description fixes wrong ticket, should be #104

good point. I've updated that

@filiphr
Copy link
Contributor Author

filiphr commented Jan 5, 2024

I've squashed all the commits and I've added SDKMAN as an action.

For this to work on the CI people will need to do something like:

source "$HOME/.sdkman/bin/sdkman-init.sh"
sdk install java 21.0.1-graal 1>&2
sdk use java 21.0.1-graal 1>&2

The sdk install is needed because the CI will not have the needed JDK. If the specified JDK is installed then sdk install is a noop (won't faill).


Aside from this approach, I have also been looking into an alternative. However, it would require a change in all scripts.

The calculate script can look like

function java_to_use() {
    echo "21.0.1-graal"
}

function run_submission() {
  JAVA_OPTS=""
  time java $JAVA_OPTS --class-path target/average-1.0.0-SNAPSHOT.jar dev.morling.onebrc.CalculateAverage_<username>
}

The java_to_use is optional and if omitted then the default one is used. We would then have a helper.sh which looks like

source $HOME/.sdkman/bin/sdkman-init.sh

function sdk_use_java() {
  if [ -z "$1" ]; then
    echo "Usage: sdk_use_java <candidate>"
    exit 1
  fi
  java_to_use="$1"
  sdk install java ${java_to_use} 1>&2
  sdk use java ${java_to_use} 1>&2
}

if [ -n "$(LC_ALL=C type -t java_to_use)" ] && [ "$(LC_ALL=C type -t java_to_use)" = function ]; then
  sdk_java=$(java_to_use)
  sdk_use_java ${sdk_java}
fi

java -version

the evaluate.sh will need to then have before the loop

source ${CALCULATE_FILE}
source ./helper.sh

and in the loop the diff would be

diff <(run_submission) ${sample%.txt}.out

Similar chnage would be needed for the evaluate.sh and we would most likelt need to add a run.sh that would then run the calculate as well.

Let me know what you think about this idea.

… that the calculate file exists for the user
@gunnarmorling
Copy link
Owner

Could we somehow pre-install all the (currently) used distributions?

@gunnarmorling
Copy link
Owner

Could we somehow pre-install all the (currently) used distributions?

Any thoughts on this, @filiphr? Or should we close it for now?

@filiphr
Copy link
Contributor Author

filiphr commented Jan 11, 2024

Yes we can do that. I've been away with a really bad internet connection. I'm back on Sunday, will be able to look into it then

@gunnarmorling
Copy link
Owner

Ok, closing for now. Thx for looking into this, @filiphr!

@gunnarmorling
Copy link
Owner

Gave this another try, see #535.

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.

Run test suite as part of PR build
3 participants