Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

6 Commits

Repository files navigation

GitHub Actions

GitHub Actions Tests, to help learn github action easily, Just the basics to get you started with some clearity

The File structure details

|-- github-actions (repository)
| |__ .github
| └── workflows # contains number of workflow actions to run
| └── my-workflow.yml
| └── actions # contains number of actions used in you workflows
| └── my-action.yml
| └── scripts # contains number of scripts used in you workflows
| └── my-script.sh
| └── FUNDING.yml # if enabled github sponsor



WORKFLOWS

Workflows to run .github/workflows/main.yml

name:GitHub-Action-Name # GitHub-Action-Nameon : [puch|pull_request|issues] # When to run, for more use with comma as `[pull_request, issues]`#ORon : # when and which branch to runpush:
branches: [ main ]pull_request:
branches: [ main ]issues:
branches: [ main ]#ORon : # Schedule at a time to runschedule: # schedule to run on UTC timezone
- cron: "30 1 * * *"# format: min[0:59] hr[0:23] day[1:31] month[0-11] weekday[0-6]; week-0:sun, week-6:satworkflow_dispatch: # Allows you to run this workflow manually from the Actions tabjobs:
example-job: # Job tag-nameruns-on: ubuntu-latest # platform to run on, options available [ubuntu-latest|windows-latest|macos-latest]steps: # Steps to follow
- name: Checkout # Job Steps-nameuses: actions/checkout@v2 # ACTION to use, defaults can be used from github's 'actions/*' repository as per need
- name: Connect to PostgreSQL # Job Steps-namerun: node client.js # SCRIPT to run, direct or via bash scriptsenv: # .env variables to use if anyPOSTGRES_HOST: postgres # .env variable namesPOSTGRES_PORT: 5432mysecret: ${{secrets.MySECRET}} # Any secret made on repository secrets, can access here via variable `secrets.variableName`
- name: Run build scriptrun: ./.github/scripts/hello.sh # location of bash script, to runshell: bash # used if running from any bash scripts, for other types, use `[bash|pwsh|python|sh|cmd|powershell]` as per needexample-job2:
runs-on: ubuntu-latestname: A job to say hellosteps:
- name: Checkout # Job Steps-nameuses: actions/checkout@v2 # To use the repository's private custom action, you must checkout the repository
- name: Hello world action stepid: hello-variable # to access the actions `outputs:` block result, and store in it, here in 'hello-variable'uses: ./.github/actions/action.yml # custom actionswith: # to pass any input variables insde your used action file mentioned under `uses:` blockinput-variable-name: 'data value'input-variable-name2: 'data value2'
- name: Get the output result # Use the output from the `hello` steprun: echo "The output was ${{ steps.hello-variable.outputs.out-variable-name }}"
Sequential jobs
# Sequential jobsjobs:
setup:
runs-on: ubuntu-lateststeps:
- run: ./setup_server.shbuild:
needs: setup # must pass setup, to run furtherruns-on: ubuntu-lateststeps:
- run: ./build_server.shtest:
needs: buildruns-on: ubuntu-lateststeps:
- run: ./test_server.sh

Remember !

WORKFLOWS runs as per sheduled mentioned (under on: block), and uses actions (under uses: block if any) and scripts (under run: block if any) as needed



ACTIONS

Actions to run on any workflows .github/actions/action.yml

name: 'My Action Name'# Action Namedescription: 'My action Description'# Overview of action, what it will doinputs:
input-variable-name: # id of input variabledescription: 'Who to greet'# small overviewrequired: true # required variable or notdefault: 'World'outputs:
output-variable-name: # id of output variabledescription: 'my output result'# small overviewruns:
using: 'node12'# version of platformmain: 'index.js'# file to pass your input variables, as well as return at output variable

Install this two before writing your index.js file

npm install @actions/core
npm install @actions/github

index.js

constcore=require('@actions/core');constgithub=require('@actions/github');try{constinput=core.getInput('input-variable-name');// get input defined in actions filename 'action.yml'console.log(`my input : ${input}`);constoutput="You have learnt somthing today, good luck !";core.setOutput("output-variable-name",output);// set output defined in actions filename 'action.yml'// Get the JSON webhook payload for the event that triggered the workflowconstpayload=JSON.stringify(github.context.payload,undefined,2)console.log(`The event payload: ${payload}`);}catch(error){core.setFailed(error.message);}



SCRIPTS

contains bash files as per the requirement .github/scripts/script.sh

# hello.shecho"hello world, this is my first github action script"



Github Sponsor

If you enabled github sponsor then add .github/FUNDING.yml with your details

github: [USERNAME1,USERNAME2] # to add github users as sponserpatreon: USERNAME # to add patreon usernameopen_collective: USERNAME # to add open collective usernameko_fi: USERNAME # to add buy me coffee usernameissuehunt: USERNAME # to add issuehunt usernamecustom: [LINK1,LINK2,....LINK-N] # to add any custom link

About

GitHub Actions Tests, with little description to understand how it works

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors