I would like to setup my workflow to do the following:
In my .github/workflows
the on
directives applies to all jobs so it won't work in my case. On the other hand, the action/upload-artifact
only works within the same workflow.
What is the proper way to achieve the described workflow?
on: push
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v1
with:
submodules: true
- name: Build
run: make all
- uses: actions/upload-artifact@v2
with:
name: build
path: dist/
- name: Deploy to GitHub Pages
filters: # <-----<<<< What I would like to do
branch: master
uses: JamesIves/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: dist/html
If you do want to trigger a workflow from within a workflow run, you can use a personal access token instead of GITHUB_TOKEN to trigger events that require a token. You'll need to create a personal access token and store it as a secret.
Workflows are defined in the . github/workflows directory in a repository, and a repository can have multiple workflows, each of which can perform a different set of tasks.
A workflow run is made up of one or more jobs , which run in parallel by default. To run jobs sequentially, you can define dependencies on other jobs using the jobs.
You could add conditions to your steps and simply skip parts which aren't needed, see jobs.<id>.steps.if
. As for what to check, github
context is a goldmine of various data related to currently running workflow. For example
github.event_name string The name of the event that triggered the workflow run.
github.ref string The branch or tag ref that triggered the workflow run.
github.head_ref string The head_ref or source branch of the pull request in a workflow run.
and so on.
Just a note that parts mentioned in documentation are just a tip of an iceberg; github.event
contains wall of useful stuff. It's best to take a look in some test workflow and see what each event provides.
Something like that should work:
- name: On any event (pull-request, push on any branches)
uses: some/action
- name: Only when master is pushed
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: some/action
- name: Only when a tag is pushed
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
uses: some/action
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With