Wondering why my release GitHub workflow generated 3 GitHub Actions #198045
-
🏷️ Discussion TypeQuestion 💬 Feature/Topic AreaWorkflow Configuration Discussion DetailsI am continuing my journey of learning how to use GitHub Flow. I have three environments: development, staging, and production. I did have all three environments in 3 different jobs in one workflow file. However, I've learned that it might be better to refactor that YAML into two YAML files, one with a different name: Single Workflow Release (for production environment)
on:
release:
workflow_dispatch: # manual
jobs:
production-deploy:
if: github.event_name == 'release'
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v6
- name: Print value from ENVIRONMENT
run: echo ${{ vars.DISPLAY_TEXT }}Could what I'm seeing be caused by there being 3 environments? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
This comment was marked as spam.
This comment was marked as spam.
-
|
@Rod-at-DOH I don't think this is being caused by the fact that you have 3 environments What I think is happening is that your workflow is subscribed to the on:
release:
workflow_dispatch:When So the most likely explanation is that when you created/published the release, GitHub emitted multiple release actions for that same release, and your workflow responded to each one. That would explain why you saw 3 nearly identical runs, all pointing to the same workflow file and all waiting for approval on the same I would separate that from environments, because If your goal is "run this once when I publish a release," I would narrow the trigger like this: name: Single Workflow Release (for production environment)
on:
release:
types: [published]
workflow_dispatch:
jobs:
production-deploy:
if: ${{ github.event_name == 'release' || github.event_name == 'workflow_dispatch' }}
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v6
- name: Print value from ENVIRONMENT
run: echo ${{ vars.DISPLAY_TEXT }}A few details that may help:
If you want to confirm this in your repo, a simple way is to print the event action in the workflow once: - name: Debug event
run: echo "event=${{ github.event_name }} action=${{ github.event.action }}"My guess is that those 3 runs would show different So in short: I would not blame the 3 environments. I would blame the unfiltered References: |
Beta Was this translation helpful? Give feedback.
-
|
Hi Rod-at-DOH, Welcome to the journey of learning GitHub Flow! It's completely normal to run into these quirks when you're first getting started. To answer your question directly: No, the 3 environments are not causing this. Defining multiple environments simply tells GitHub they exist; it doesn't automatically multiply your workflow runs. The Root CauseWhen you use the on:
release:
GitHub Actions defaults to listening for all release activities. According to GitHub's documentation, this includes:
When you create and publish a release through the GitHub web UI, GitHub doesn't just send one signal. It fires a rapid sequence of events (usually The FixTo ensure your workflow only runs exactly once when you actually publish a release, you just need to restrict the activity type to Update your name: Single Workflow Release (for production environment)
on:
release:
types: [published]
workflow_dispatch: # manual
jobs:
# ... rest of your workflow remains the same
With |
Beta Was this translation helpful? Give feedback.
@Rod-at-DOH I don't think this is being caused by the fact that you have 3 environments
What I think is happening is that your workflow is subscribed to the
releaseevent too broadly:When
releaseis configured that way, GitHub Actions listens to all release activity types by default, not just the final "publish" moment. According to the GitHub Actions docs, thereleaseevent can fire forpublished,unpublished,created,edited,deleted,prereleased, andreleased. The workflow syntax docs also say that if multiple triggering activity types happen as part of the same action, GitHub can create multiple workflow runs.So the most likely explanation is that…