I use github actions for integration tests.
The problem is, that the tests should not run on multiple instances with the same configuration in parallel (the test would fail).
But, it can be run once with let's say configuration 1 and once with configuration 2 in parallel.
As this blog post describes, it is not possible to secure that a workflow does not run in parallel.
Is there any way to switch configurations, that configuration 1 and configuration 2 alternately?
In that case, it would not be that likely that the workflow workflows with the same configuration runs in parallel (I could add more configurations if needed).
For example, this could be done by a global and writable (for the workflow) variable that is alternately 1 or 2 and the workflow picks that configuration.
Example workflow(the secret confToSwitch
should be switched):
name: test
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: "load configuration"
run: echo "configuration=$conf" >> ./conf
env:
conf: ${{ secrets.confToSwitch }}
- name: "integration tests"
run: "mvn -B integration-test"
Passing values between steps and jobs in a workflow If you generate a value in one step of a job, you can use the value in subsequent steps of the same job by assigning the value to an existing or new environment variable and then writing this to the GITHUB_ENV environment file.
(After the setting, you can use environment variables like this in your project.) To add a secret to your repository, go to your repository's Setting > Secrets , click on Add a new secret .
github.ref. string. The branch or tag ref that triggered the workflow run. For workflows triggered by push , this is the branch or tag ref that was pushed. For workflows triggered by pull_request , this is the pull request merge branch.
You can try a matrix
configuration with:
name: test
on: [push]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
token: [token1, token2, etc...]
steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: "load configuration"
run: echo "configuration=$conf" >> ./conf
env:
conf: ${{ matrix.token }}
- name: "integration tests"
run: "mvn -B integration-test"
This will create N
jobs where N
is the number of tokens in the list and each job with conf: ${{ matrix.token }}
will resolve to a token in the list for the current job.
I think it may also be possible to store your tokens as secrets and setup the matrix like:
strategy:
matrix:
token: ["${{secrets.token1}}", "${{secrets.token2}}", etc...]
However, I haven't tested this.
I found a trick to make the secrets tokens work:
token1
, token2
, etcstrategy:
matrix:
token: [token1, token2]
env:
token: ${{secrets[matrix.token]}}
${{env.token}}
(when operating within an expression context) or $token
(in bash).The environment variable will still remain a secret, so you don't loose anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With