Skip to content

Instantly share code, notes, and snippets.

@nashmaniac
Last active June 2, 2020 02:09
Show Gist options
  • Save nashmaniac/0b2d2884bfde8282167d4ff53646a0dd to your computer and use it in GitHub Desktop.
Save nashmaniac/0b2d2884bfde8282167d4ff53646a0dd to your computer and use it in GitHub Desktop.
Step Definition
# Under each job there is a keyword called steps
# steps contains list of step
# In here will simply explain single step block
# as steps are list, if one fails, the next steps are skipped. There are ways to trigger it to.
# name of the step
name: name of the step
id: sample_id # needed if this step has output to be used in other steps
run: echo 'Hello World' # command we want to run
# why GitHub Actions are so powerful
# because it has a action marketplace that will let you
# use other's actions and publish yours
name: checkout code at current push
uses: actions/checkout@v1
# here actions is the username, checkout is the repo name
# v1 is the tag
# you can use branch name, sha or tag after @
# but always safe to use tag as it is static
# sometimes some action might take input from outside to act on
# you can pass this using with keywords
name: Running simple steps
uses: actions/hello-world-javascript-action@master
with:
who-to-greet: 'Mona the Octocat'
## Other than using public actions you can also use your own actions that lives in your repo
name: Local Action
uses: ./.github/actions/hello
# for this to succeed make sure you have a file named
# ./.github/actions/hello/action.yaml in your repo
# I will go more into it in my subsequent blogs
# You might want to run a docker container in your steps
# simply use this
name: Running docker container
uses: docker://python:3
# this will bootup a python:3 docker container
# You can have env variables scoped to our steps only
name: Env Variable Steps
run: echo $HELLO_WORLD
env:
HELLO_WORLD: hello-world # will not be available to other steps
# sometimes you might want to run a step always
name: Run only in case of Failure
run: echo the workflow failed
if: ${{ failed() }} # possible values are failed(), always(), success()
# also you can run a steps based on event type and branches too
name: Run only when push to master
run: echo the code is pushed to master branch
if: ${{ github.event_name == 'push' && github.ref == 'master' }}
# a job might also have output that we can use in subsequent steps too
# let's assume we have a step with id second_step in any step before this step and it has a output named time.
name: Print Previous Step Output
run: echo ${{steps.second_step.outputs.time}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment