Skip to content

Replace Travis CI with GitHub Actions#975

Merged
coriolinus merged 17 commits intoexercism:masterfrom
dgunay:master
Oct 15, 2020
Merged

Replace Travis CI with GitHub Actions#975
coriolinus merged 17 commits intoexercism:masterfrom
dgunay:master

Conversation

@dgunay
Copy link
Copy Markdown
Contributor

@dgunay dgunay commented Oct 6, 2020

Addressing this issue: #974

One note: this only runs the tests on the latest Ubuntu. I saw there is a different process for running the tests on Windows - that would probably require more work to configure correctly. Let me know if anything needs to be changed.

@coriolinus
Copy link
Copy Markdown
Member

One thing I don't see in this PR is a replication of the stable/beta/nightly and environment matrix. For example, on Travis, both stable and beta channels run both with and without DENYWARNINGS=1, but allows failures for the beta channel with warnings. The nightly channel runs the check-exercises.sh script with BENCHMARKS=1 enabled. I don't see anything in this current configuration selecting a Rust channel at all. Did I miss it?

Comment thread .github/workflows/tests.yml Outdated
Co-authored-by: Sascha Mann <git@mail.saschamann.eu>
@dgunay
Copy link
Copy Markdown
Contributor Author

dgunay commented Oct 6, 2020

@coriolinus You're right, I did not replicate that. I'll try and implement that.

Comment thread .github/workflows/tests.yml Outdated
Comment thread .github/workflows/tests.yml Outdated
Comment thread .github/workflows/tests.yml Outdated
Comment thread .github/workflows/tests.yml Outdated
Comment thread .github/workflows/tests.yml
@coriolinus
Copy link
Copy Markdown
Member

Another thing I just noticed: in several places in _test, scripts look for a travis environment variable. A representative example:

if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then

That will have to be dealt with one way or another. At the most basic level, we can re-write the scripts to use a different mechanism to detect whether they're running in a pull request, or we can inject that environment variable if the action was triggered by a pull request, as opposed to just checking the most recent commit of the master branch. I have a mild preference for rewriting the scripts to stop referencing Travis, but I suspect that we'd need to inject our own environment variable anyway, so I don't mind leaving the scripts as they are.

@dgunay
Copy link
Copy Markdown
Contributor Author

dgunay commented Oct 7, 2020

Fiddling with the job configuration in a separate branch to avoid spamming this PR - one worrying thing I've noticed is that the scripts (I can see the ones with the old TRAVIS_ env variables at least) fail silently while reporting success in the GitHub Actions UI:

image

@coriolinus
Copy link
Copy Markdown
Member

Interesting. I'm having a hard time replicating that error--I don't know what git version they're using, but it appears to be different than mine--but I think we can at least improve error propagation by injecting

set -e -o pipefail

into the affected scripts near the top.

@coriolinus
Copy link
Copy Markdown
Member

Also, the error seems to imply that master is not in the working tree, which suggests that something in the checkout has failed; that branch should always be available.

@dgunay
Copy link
Copy Markdown
Contributor Author

dgunay commented Oct 7, 2020

I believe this might be what's happening: https://github.bokerqi.topmunity/t/git-ambiguous-argument-master/17832/2

I think changing the script to refer to origin/master instead of just master might fix it.

@SaschaMann
Copy link
Copy Markdown
Contributor

I don't know what git version they're using

git 2.28.0

@dgunay
Copy link
Copy Markdown
Contributor Author

dgunay commented Oct 7, 2020

Interesting. I'm having a hard time replicating that error--I don't know what git version they're using, but it appears to be different than mine--but I think we can at least improve error propagation by injecting

set -e -o pipefail

into the affected scripts near the top.

This makes the jobs fail at least, but changing to origin/master did not help. I'll try seeing what's wrong.

@dgunay
Copy link
Copy Markdown
Contributor Author

dgunay commented Oct 8, 2020

Added another step to each job to checkout the master branch locally - turns out that wasn't happening when I had a look with git branch -a. Will have something new to look at soon.

Various commits to a branch in the fork, squashed to avoid spamming the PR:

* test1

* test2

* try putting entire expression in curly braces

* big commit

* delete comment

* delete continue on error

* delete not linting lines

* Update tests.yml

* comment out compilation job

* add temp branch

* uncomment compilation job

* try using deny warnings

* forgot what i did

* fix nightly toolchain

* try toolchain again

* try toolchain again

* try toolchain again

* add travis env var

* try changing master to origin/master to make actions not fail

* add set -e -o pipefail to script

* fail fast during CI for pull requests

* add check PR files

* look at git branch -a

* try to check out master first

* see if remotes origin master works

* fix master branch path

* checkout master for configlet job

* fix master ref in ensure readmes updated

* check out master for nightly
@dgunay
Copy link
Copy Markdown
Contributor Author

dgunay commented Oct 8, 2020

As far as I am aware, the remaining things left to fix:

  1. I'm not sure how to conditionally set TRAVIS_PULL_REQUEST based on whether or not the action is being triggered by a pull request.

  2. Still not quite sure how to do continue-on-error when on the beta toolchain with DENYWARNINGS=1

@coriolinus
Copy link
Copy Markdown
Member

I haven't experimented with this, but in the docs, I see the following snippet:

env:
  my_env_var: ${{ <expression> }}

This is tempting, but apparently wrong, because github actions syntax does not support inline conditional expressions. Instead, we should keep looking. For example:

github.event object The full event webhook payload. For more information, see "Events that trigger workflows."

Follow through with the pull request object docs, the commands docs, and a bit of bash variable expansion magic and it looks like what we need is something like this:

steps:
  - name: set TRAVIS_PULL_REQUEST
    env:
      PR_NUMBER: ${{ github.event.pull_request.number }}
    run: echo "TRAVIS_PULL_REQUEST=${PR_NUMBER:-false}" >> $GITHUB_ENV

Did the suggestion here fail? If yes, how?

dgunay added 2 commits October 8, 2020 21:46
commit 5790f28ef86d72c9bcc57344d6f5064d101c45f0
Author: Devin gunay <devingunay@gmail.com>
Date:   Thu Oct 8 21:45:55 2020 -0700

    probably working gh actions configuration

commit 4c07754
Author: Devin gunay <devingunay@gmail.com>
Date:   Thu Oct 8 21:43:21 2020 -0700

    test if whole job fails

commit 666653b
Author: Devin gunay <devingunay@gmail.com>
Date:   Thu Oct 8 21:38:50 2020 -0700

    test failure on CI w denywarnings

commit 641db7e
Author: Devin gunay <devingunay@gmail.com>
Date:   Thu Oct 8 21:25:41 2020 -0700

    edit script to check cont on error

commit 85801de
Author: Devin gunay <devingunay@gmail.com>
Date:   Thu Oct 8 21:18:18 2020 -0700

    fix toolchain and try continue on error

commit 1c2e590
Author: Devin gunay <devingunay@gmail.com>
Date:   Thu Oct 8 21:08:11 2020 -0700

    remove travis pr echo

commit 4a623fc
Author: Devin gunay <devingunay@gmail.com>
Date:   Thu Oct 8 21:03:11 2020 -0700

    print pr var

commit c79f0c1
Author: Devin gunay <devingunay@gmail.com>
Date:   Thu Oct 8 21:01:06 2020 -0700

    try travis pr again

commit 21ddc40
Author: Devin gunay <devingunay@gmail.com>
Date:   Thu Oct 8 20:55:52 2020 -0700

    set travis pr var conditionally

commit 3a580b6
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 17:05:25 2020 -0700

    check out master for nightly

commit 67bb71d
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 17:02:51 2020 -0700

    fix master ref in ensure readmes updated

commit 05c6951
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 17:00:44 2020 -0700

    checkout master for configlet job

commit 9e31662
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 16:58:55 2020 -0700

    fix master branch path

commit 749a92c
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 16:55:21 2020 -0700

    see if remotes origin master works

commit 33a0704
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 16:54:21 2020 -0700

    try to check out master first

commit 8739869
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 16:51:03 2020 -0700

    look at git branch -a

commit 96001e2
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 16:46:16 2020 -0700

    add check PR files

commit 2be04c5
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 16:38:02 2020 -0700

    fail fast during CI for pull requests

commit 02101b2
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 16:36:08 2020 -0700

    add set -e -o pipefail to script

commit c5e255a
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 16:27:02 2020 -0700

    try changing master to origin/master to make actions not fail

commit 3b4395a
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 00:47:17 2020 -0700

    add travis env var

commit 497d3a3
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 00:26:24 2020 -0700

    try toolchain again

commit 359269f
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 00:25:37 2020 -0700

    try toolchain again

commit 04df9cb
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 00:24:41 2020 -0700

    try toolchain again

commit 42b6e16
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 00:18:00 2020 -0700

    fix nightly toolchain

commit 2c7354d
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 00:17:18 2020 -0700

    forgot what i did

commit 7560f0b
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 00:09:38 2020 -0700

    try using deny warnings

commit 80b6d76
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 00:07:15 2020 -0700

    uncomment compilation job

commit 5badd46
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 00:06:24 2020 -0700

    add temp branch

commit ef58cdb
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 00:05:27 2020 -0700

    comment out compilation job

commit 0ef5ed2
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 00:04:30 2020 -0700

    Update tests.yml

commit 66db311
Author: Devin Gunay <devingunay@gmail.com>
Date:   Wed Oct 7 00:00:40 2020 -0700

    delete not linting lines

commit 803a507
Author: Devin Gunay <devingunay@gmail.com>
Date:   Tue Oct 6 23:59:38 2020 -0700

    delete continue on error

commit c34c8f6
Author: Devin Gunay <devingunay@gmail.com>
Date:   Tue Oct 6 23:58:33 2020 -0700

    delete comment

commit dbd4e1c
Author: Devin Gunay <devingunay@gmail.com>
Date:   Tue Oct 6 23:57:11 2020 -0700

    big commit

commit ba883ef
Author: Devin Gunay <devingunay@gmail.com>
Date:   Tue Oct 6 23:41:41 2020 -0700

    try putting entire expression in curly braces

commit 524b3e7
Author: Devin Gunay <devingunay@gmail.com>
Date:   Tue Oct 6 23:40:25 2020 -0700

    test2

commit 96c5547
Author: Devin Gunay <devingunay@gmail.com>
Date:   Tue Oct 6 23:39:37 2020 -0700

    test1
@dgunay
Copy link
Copy Markdown
Contributor Author

dgunay commented Oct 9, 2020

Okay, I think I've got something that works as intended. Things addressed:

  • I made sure to set the selected toolchain as the default during rustup
  • @coriolinus your suggestion for setting TRAVIS_PULL_REQUEST worked nicely
  • I got continue-on-error to work by copying and pasting it for each step that needed it.

I tested it by altering the check-exercises.sh script to fail on beta with DENYWARNINGS=1.

I'm not super happy about the copying and pasting but perhaps someone with more knowledge of GitHub Actions could make it more DRY.

By the way, check-exercises.sh seems to fail right now on stable with DENYWARNINGS=1. I can reproduce this locally. That's only because when I push, it runs all of the tests so not sure it's a concern right now.

@dgunay
Copy link
Copy Markdown
Contributor Author

dgunay commented Oct 9, 2020

Oh, another thing - is nightly supposed to be run both with and without DENYWARNINGS?

@coriolinus
Copy link
Copy Markdown
Member

coriolinus commented Oct 9, 2020

Great! At this point, it seems that the only things remaining will be to clean up some of the comment-only edits to the test scripts, and actually test the whole thing.

It is definitely possible to reduce duplication within the source file by using some YAML Anchor and Alias trickery, but I have mixed feelings about that; I've seen the technique used to produce very dense configurations which were almost impossible to understand. I don't oppose trying it out, but I'd reserve the right to ask to revert those changes. I'm sorry to be so vague about the acceptance criteria for this, but I'm finding them hard to verbalize. All I can say is that if the anchor/aliased config is readable and well-documented, I'll probably accept it; if I find it confusing, I'd ask it to be reverted.

Thanks for spotting the DENYWARNINGS failure on stable! I'm working on a fix for that now. #977

nightly does not need DENYWARNINGS; we only run nightly at all in order to run the benchmarks.

@dgunay
Copy link
Copy Markdown
Contributor Author

dgunay commented Oct 15, 2020

Sorry for the lack of activity - school kind of took over my life for a bit. Do you have any recommendations for how to test it? Otherwise I guess I was just going to run it manually in these scenarios (third dimension not pictured: with and without failing code):

stable beta nightly
direct push
pull request

I do hope there's a good automated way of testing GitHub actions because it seems like a lot of work...

@coriolinus
Copy link
Copy Markdown
Member

No worries about lack of activity; this is volunteer work for all of us, and we've all got other things going on in our lives.

I don't think you need to worry about pushing some code which behaves differently according to the stable/beta/nightly dimension; manual verification that those stages have been run is sufficient. Testing direct push to master is probably not necessary either: we know that it'll be running the same actions as a pull request, and it'll be straightforward to verify whether or not those steps are complete after merging this PR.

To my mind, what we really want to demonstrate are these cases:

  • most recent commit to a PR for which all is good, succeeds
  • at least one example for each action which causes that action alone to fail independently. Probably the simplest examples:
    • compilation failure in an exercise's example
    • wrong number of #[ignore] lines in a test file
    • README for an exercise has an edit
    • benchmarking fails for an exercise with a bench

As for how to demonstrate this, I think creating a PR based on this PR targeting your own fork of this repo will cause the actions to run. Create some innocuous commit in that PR to demonstrate the success case, then add / revert commits to demonstrate each of the failure cases. Once that is all done, just link to that separate PR here, and we can inspect to verify that things worked as expected.

@coriolinus coriolinus linked an issue Oct 15, 2020 that may be closed by this pull request
@coriolinus
Copy link
Copy Markdown
Member

I did #983 to test that these actions work as expected; they succeeded very nicely. I'm going to do a little bit of cleanup now, then approve/merge.

Changing the behavior of the scripts is out of scope of this PR.
If we see erroneous CI in the future, we can fix things then.
We therefore don't need new comment-only changes in the scripts.
Copy link
Copy Markdown
Member

@coriolinus coriolinus left a comment

Choose a reason for hiding this comment

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

Thanks for doing all this work @dgunay!

@coriolinus coriolinus merged commit b5ef4de into exercism:master Oct 15, 2020
@dgunay
Copy link
Copy Markdown
Contributor Author

dgunay commented Oct 15, 2020

@coriolinus Thank you and @SaschaMann for the feedback! Glad I could help and learn a bit about GitHub Actions in the process.

petertseng added a commit that referenced this pull request Nov 16, 2020
This was supposed to have been done with the move to GitHub Actions:
#975
#974
#982

Better late than never
petertseng added a commit that referenced this pull request Nov 17, 2020
When moving off of Travis in
#975, there were some instances of
TRAVIS_PULL_REQUEST left over as a transitionary strategy.

Now we have been hurt by leaving TRAVIS_PULL_REQUEST in:
In #1006 a new GitHub Actions job
was added that forgot to set TRAVIS_PULL_REQUEST and caused incorrect
behaviour.

So let's remove TRAVIS_PULL_REQUEST and instead change it to
GITHUB_EVENT_NAME.

Documentation:
https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables
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.

Moving from Travis to GitHub Actions

3 participants