Search code examples
cypressgithub-actionsautomation-testing

how to configure scheduled tests with different branches and environments?


I have a question about GitHub Actions - Cypress testing mentality. We have 2 different environments for development; let's call them firstEnv and secondEnv.

Developers are pushing their codes on firstEnv. Once in a week we are having releases from firstEnv to secondEnv; so automation tests are different from each other; since there are differences among them.

I'm holding automation code for secondEnv in "main" branch and for firstEnv, another branch called "develop-branch". When release happens I'm merging develop-branch to main branch; because two environments become same and can be tested by main.

So here is the question I want to test each environment by its own branch periodically (e.g. firstEnv with "develop-branch" | secondEnv with "main" at 2 am). Should I prepare two different yaml files for different environments? If so, in which branch I should hold these files?

I tried to add two yaml files for main branch like firstEnv.yaml and main.yaml; however they both used the code in main branch.


Solution

  • You can use reusable workflows to avoid duplication. You should have this workflow in both branches, so make sure you merge branches as it is needed.

    Then you should create one workflow for the firstEnv and one for the secondEnv. These will be with schedule trigger.

    The secondEnv should refer to workflow from the main branch like below:

    jobs:
      call-workflow-passing-data:
        uses: octo-org/example-repo/.github/workflows/reusable-workflow.yml@main
        with:
          config-path: .github/labeler.yml
        secrets:
          envPAT: ${{ secrets.envPAT }}
    

    And the firstEnv should reference the workflow from develop-branch like octo-org/example-repo/.github/workflows/reusable-workflow.yml@develop-branch.

    You need to make sure that you fetch correct revision

    If you take a look at the documentation here you will see that the GITHUB_SHA associated with the on: schedule event is "Last commit on default branch." This is what will be checked out by default when you use the actions/checkout action.

    name: Release Management
    on: 
      schedule:
       - cron: "*/5 * * * *"
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v2
            with:
              ref: develop-branch
    

    You may first skip reusable workflows and try just scheduled workflows. You should have them on the main branch but keep in mind to checkout the correct revision for develop-branch.