Reputation: 329
If I have a workflow in two branches "dev" and "main" with the same name and content, which one takes precedence? Or will both workflows run? What happens if the content of the two workflows is different, but the workflow name is the same?
Assume I have this workflow below on the main branch, but I have a slightly different version on a "dev" branch with the same file name and trigger (both on push branches dev). Would both execute on a push to "dev"?
name: .NET Core CI
on:
push:
branches:
- dev
env:
AZURE_WEBAPP_NAME: ghactiontest # set this to your application's name
AZURE_WEBAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '6.0' # set this to the dot net version to use
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checkout the repo
- uses: actions/checkout@main
# Setup .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# Run dotnet build and publish
- name: dotnet build and publish
run: |
dotnet restore
dotnet build --configuration Release
dotnet publish -c Release -o '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
# Deploy to Azure Web apps
- name: 'Run Azure webapp deploy action using publish profile credentials'
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }} # Replace with your app name
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }} # Define secret variable in repository settings as per action documentation
package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/myapp'
Upvotes: 1
Views: 4555
Reputation: 329
I tested this with a simple hello world workflow on the "main" and "dev" branches. If there is an "on push" trigger for a given branch, the workflow must exist on that branch. A workflow on "main" with a trigger for both "main" and "dev" will only execute on a push to "main" if there's no corresponding workflow on "dev".
name: .NET Core CI Cert
on:
push:
branches:
- cert
- main
jobs:
my-job:
runs-on: ubuntu-latest
steps:
- name: my-step
run: echo "Hello World Cert Branch!"
Upvotes: 1
Reputation: 1127
Since all workflows are suppose to be located in .github/workflows
directory and they cannot be inside sub directories theoretically you cannot create more than one workflow with same name in this directory.
To answer your other question, if you want to run a workflow for a specific branch you can use the branch syntax as following:
on:
push:
branches:
- main
Just create your workflows with different names and let them get triggered when push or pull request event is triggered for respective branch.
Upvotes: 0
Reputation: 3443
Normally this workflow will run for both dev
and main
- can you post your exact workflow?
Two workflows with the same name will also run separately and will be considered two different workflows with two different workflow_id
s - but they will appear using the same name.
Upvotes: 0