GitHub Actions
Topics covered:
What is CI/CD?
What is GitHub Action?
Creating GitHub Workflows
Demonstration using Python
Create repository
Create
src/app.py
print("Hello there!")
Add
.github/workflows/deploy.yml
name: Deploy
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Run Code
run: python src/app.py
Extending Python Example
Update
src/app.py
"""
A test python application
"""
print("Hello there!")
for i in range(2):
print(i)
for i in range(3):
print(i)
Add
requirements.txt
pylint
Add
.github/workflows/lint.yml
name: Lint check
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install dependencies
run: python -m pip install -r requirements.txt
- name: Run Linting
run: pylint src/**/*.py
Demonstration using ReactJS
Run:
npm install gh-pages --save-dev
Workflow file
name: Deploy to GitHub Pages
on:
push:
branches:
- main
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: '18'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Deploy to gh-pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: build
package.json
{
"name": "react-example",
"homepage": "https://<username>.github.io/<repo-name>",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"gh-pages": "^6.1.1"
}
}
Last updated