Previously
When testing roles before GitHub Actions, it was assumed that you’d only have one repository for each role. But with the addition of collections, that is no longer the case. Your collection can now have multiple roles, modules, and often you do not need to test everything when a role or a set of modules has changed.
Using GitHub Actions, there’s a way to do this.
Now with GitHub Actions
Using GitHub Actions and workflow, we can configure what actions will trigger a test (workflow) run. In my example, which I do use on all of my collections, I set only on Pull Request and Push will the tests be triggered.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
name: "community.zabbix.zabbix_agent" on: push: paths: - 'roles/zabbix_agent/**' - 'molecule/zabbix_agent/**' - '.github/workflows/zabbix_agent.yml' pull_request: paths: - 'roles/zabbix_agent/**' - 'molecule/zabbix_agent/**' - '.github/workflows/zabbix_agent.yml' jobs: zabbix_agent: runs-on: ubuntu-18.04 env: PY_COLORS: 1 ANSIBLE_FORCE_COLOR: 1 strategy: fail-fast: false ... |
So if you notice in the example, configured my test to run on both push and pull_request. Unfortunately, GitHub Actions doesn’t support anchors yet so I couldn’t use them.
Why did I choose those paths?
'roles/zabbix_agent/**' – sets GitHub actions to watch all the files underneath the role zabbix_agent
'molecule/zabbix_agent/**' – watches all the files part of the molecule testing for zabbix_agent
'.github/workflows/zabbix_agent.yml' – the file that runs the GitHub Action workflow itself
The code here helps ensure that only when a file used for testing or executing this role is modified will it run and ensures that you don’t waste a lot of testing time on GitHub Actions so other tests can run on other repositories. You can find more options here https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#on