What is GitHub Actions?
Easily automate all software workflows with world-class CI / CD. You can build, test, and deploy code directly from GitHub to get code review, branch management, and problem triage to work the way you want.
Practical examples
- Environmental variables (Global)
- Environmental variables (In step)
- Multiple command simplification
- Specify subfolder
- Action trigger condition (Specified folder)
- Action trigger condition (Other than the specified folder)
- Execution order of multiple jobs
- Workflow execution between repositories
- Send notification to Slack
Environmental variables (Global)
on:
push:
branches:
- mainenv:
ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY_ID }}
SECRET_ACCESS_KEY: ${{ secrets.SECRET_ACCESS_KEY }}
Environmental variables (In step)
jobs:
Build:
runs-on: ubuntu-lateststeps:
- name: install
run: yarn install
env:
ENVIRONMENT: test
Multiple command simplification
jobs:
Build:
runs-on: ubuntu-lateststeps:
- name: Install_And_Build
run: |
yarn install
yarn build
Specify subfolder
jobs:
Build:
runs-on: ubuntu-lateststeps:
- name: deploy
working-directory: source
run: |
yarn deploy
Action trigger condition (Specified folder)
on:
push:
branches:
- master
paths:
- source/**
Action trigger condition (Other than the specified folder)
on:
push:
branches:
- master
paths-ignore:
- source/**
Execution order of multiple jobs
jobs:
Build:
runs-on: ubuntu-lateststeps:
- run: TestDeploy:
needs:
- Build
runs-on: ubuntu-lateststeps:
- run: Test
Workflow execution between repositories → repository-dispatch(From)
jobs:
Backend:
runs-on: ubuntu-lateststeps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v1.1.0
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
repository: owner/repository
event-type: next
Workflow execution between repositories → repository-dispatch(To)
on:
repository_dispatch:
types: next
Send notification to Slack
jobs:
Slack:
runs-on: ubuntu-lateststeps:
- name: Slack Notify
uses: rtCamp/action-slack-notify@v2.0.1
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: build
SLACK_TITLE: Build Success
SLACK_COLOR: '#43a047'
SLACK_MESSAGE: ${{ github.repository }} Build Success
SLACK_USERNAME: ${{ github.repository }}