So I've been experimenting with new Github Actions, and tried to setup a workflow for running tests in linux environment. I already have a perfectly working Travis config which utilizes swiftenv tool:
os:
- linux
env:
language: generic
sudo: required
dist: trusty
install:
- if [ $TRAVIS_OS_NAME = linux ]; then
eval "$(curl -sL https://swiftenv.fuller.li/install.sh)";
fi
before_script:
- ... FoundationDB installation ...
script:
- swift test
I tried to port it to Github workflow:
name: FDBSwift
on:
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install swiftenv
run: eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
- name: Install FoundationDB
run: ... FoundationDB installation ...
- name: Run tests
run: swift test
but when I triggered the check, I got an error swift: command not found as if step Run tests lost context.
Eventually I got working when I just squeezed all prep work into one step along with swift test, but it feels wrong.
Apparently I'm missing something, but official documentation isn't very friendly. Can anyone please help me with this?
mackoj
(Jeffrey Macko)
2
You need to install swift or using an os with swift like macos.
Because swiftenv is not swift.
Swiftenv does exactly that, please see my Travis config or working Github Actions config.
mackoj
(Jeffrey Macko)
4
Can you share your github actions logs ?
use swift official docker image instead:
Linux:
strategy:
matrix:
tag: ['5.0', '5.1']
runs-on: ubuntu-latest
container:
image: swift:${{ matrix.tag }}
steps:
- uses: actions/checkout@v1
- run: swift test
You didn't get the original question :) I got it working eventually, but in a dirty and non-modular way. It should work without Docker (also I'm quite sure it runs inside Docker already), but for some reason context isn't saved between steps.
jechris
(JC)
8
From what I see in your config files, you're actually never using swiftenv; you're just installing it. And installing it does not install swift.
So in the end you're just relying on pre-installed swift (if any). To make sure of that could you check result of swiftenv versions in both your config?
If it doesn't install Swift, why putting all steps into one step works?
SDGGiesbrecht
(Jeremy David Giesbrecht)
10
It does install Swift.
That is what is happening. Something about the install is not surviving into the next step.
I imagine it has to do with environment variables. swiftenv modifies them to point to its install, but if the next step uses a fresh environment, then it would appear to have vanished.
If you want to debug it, you could try printing the environment at the end of the install step and also at the beginning of the test step, so that you could compare the difference. Beware though, that there might also be security keys or the like in the environment that you could spill to the whole word in the process if you are not careful how you go about it. And unless you are part of the development team for GitHub Actions, you may not be able to actually fix it anyway.
SDGGiesbrecht
(Jeremy David Giesbrecht)
11
I’m now trying to set up Git actions too. I ran across this in the documentation, which likely explains what you see:
Each run keyword represents a new process and shell in the virtual environment. When you provide multi-line commands, each line runs in the same shell. For example:
The spawning of a new shell each time loses the environment, which appears to be deliberate on GitHub’s part. (Maybe it is to prevent multiple third‐party actions compromising one another’s security?)
However, as you’ve figured out, their multiline syntax works, albeit without the clean division of results in the user interface.
ahti
(Lukas Stabe 🙃)
12
There is also this action: Swift Setup · Actions · GitHub Marketplace · GitHub which has worked well for me so far.
Swift 5.2 is now officially installed on Ubuntu runners. See this issue for discussion, as well as the Ubuntu virtual environment reference.
3 Likes