This is a beginner course on Github actions. I am creating this as a newbee who is also learning. Following this Repository will help you learn GitHub Actions as I learn too.
Event
- A triger that will kick of a Github Action.It could be a Pull Request, Push to a branch , Issue created, Closed or any thing else that you can imagine as a triggerWorkFlow
- This fines the task that will be run or an action done based on the trigger
Runners
- This is the host on which the job runns
gh repo create KiranChilledOut/LearningGithubActions --public
gh repo clone kiranChilledOut/LearningGitHubActions
.github
folder in the repository - New-Item -Type Directory -Name '.github'
cd
into the folder and great a new folder workflows
- cd .\.github\
and New-Item -Type Directory -Name 'workflows'
cd
into the workflow
folder and create files hello_world.yaml
- cd .\workflows\
and New-Item -Type File -Name 'hello_world.yaml'
vsCode
and add a 1st line the defines the workflow name
name: Hello World workflow
Next specify a trigger
on:
push:
branches:
- main
pull_request:
- main
workflow_dispatch:
on
- Keyword for the triggerpush
- trigger actionbranches
- action entitypush
action on the main
branch or a pull request
on the main
branch or a manual trigger
on the workflowNext specify a Job
jobs:
hello:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: hello world
run: write-host "hello World"
shell: powershell
goodbye:
runs-on: windows-latest
steps:
- name: goodbye world
run: write-host "goodbye World"
shell: powershell
jobs
- Specifies the actions based on the trigger.Here the jobs are hello
and goodbye
runs-on
- Specifies the host/runner the job runs on.uses: actions/checkout@v4
- this is used to use a community or a self created action. Click to know more about actions/checkoutContext
in order for the github actions to comment on an issue it needs to know some information like issue id etc. This is called Contextwrite
permissions given to it
Read and write permissions
issue_comment.yaml
Add the below code
name: Create a comment on new issues
on:
issues:
types: [opened]
jobs:
comment-with-action:
runs-on: windows-latest
steps:
- name: "dump github context"
run: |
$json = '${{toJson(github.event)}}'
Write-Output $json
shell: pwsh
github.event
was used to trigger this workflow.number
which is the issue number
Add the below step in the file issue_comment.yaml
created in the above step
- name: Create comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{github.event.issue.number}}
body: |
This is a multi-line test comment
- With GitHub **Markdown** :sparkles:
- Created by [create-or-update-comment][1]
reactions: '+1'
${{github.event.issue.number}}
is just the json tree output we saw in previous step.issue_comment.yaml
created in the above step