3

I'm currently using the "git-flow" branching model outlined here. Following that model, once I've completed work on a feature branch, I'd like to add new GitHub actions to that branch (for example, to run my feaure's automated tests) before the branch is merged.

Following the branching model, I don't want to define the actions in a workflow file on the default branch before that feature branch is merged into it. Ideally I want to add the actions on the feature branch itself before the merge, but this doesn't appear to work.

I've added the below sample workflow to my feature branch, but GitHub does not detect it. Am I missing something here, or can workflows only detected and run once they're on the default branch? If the latter is true, do people generally merge their branches, then add workflows for them?

# Name workflow
name: Test workflow

# Read only permissions
permissions: read-all

# Triggered once every 15 minutes
on:
  workflow_dispatch:
  schedule:
    - cron: '15 * * * *'

# Listing of jobs to be run
jobs:

  # Just output the Python version for now.
  python-tests:
    name: Python Tests
    runs-on: ubuntu-latest
    
    # Use the environment configured with secrets
    environment: python-test-environment
    
    # Set the working directory?
    defaults:
      run:
        working-directory: tests
       
    steps:
      # Checkout the repository
      - name: Checkout
        uses: actions/checkout@v2
        ref: 'dev-tests'
      
      # Configure Python
      - name: Set up Python 3.7
        uses: actions/setup-python@v2
        with:
          python-version: 3.7
      
      # Output the Python version
      - name: Display version
        run: python -c "import sys; print(sys.version)"

Update: I can see now that the "schedule" trigger only works on the default branch. However, removing it and just using the workflow_dispatch trigger still (on the feature branch YML file) still does not show the workflow on GitHub.

Michael Hillman
  • 1,217
  • 3
  • 15
  • 24
  • 4
    If I'm not mistaken, it's the later (_workflows are only detected and run once they're on the default branch_). To test new workflows, generally I switch my feature branch to default branch, test the workflows, and if it works, I use the original default branch back an open the PR from the feature branch to the default branch. – GuiFalourd Aug 03 '21 at 18:06

0 Answers0