Deploying Websites with GitHub Actions
Learn how to deploy different types of websites with GitHub Actions.
I
InSkillCoach
· min
Deploying Websites with GitHub Actions
Learn how to deploy different types of websites with GitHub Actions.
Deploying a React Site
1. Project Configuration
// package.json
{
"name": "mon-site-react",
"version": "1.0.0",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
}
2. GitHub Actions Workflow
# .github/workflows/react.yml
name: Deploy React App
on:
push:
branches: [ main ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./build
Deploying a Vue.js Site
1. Project Configuration
// package.json
{
"name": "mon-site-vue",
"version": "1.0.0",
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
}
}
2. GitHub Actions Workflow
# .github/workflows/vue.yml
name: Deploy Vue App
on:
push:
branches: [ main ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./dist
Deploying a Next.js Site
1. Project Configuration
// package.json
{
"name": "mon-site-next",
"version": "1.0.0",
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
}
}
2. GitHub Actions Workflow
# .github/workflows/next.yml
name: Deploy Next.js App
on:
push:
branches: [ main ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Export
run: npm run export
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./out
Deploying a Hugo Site
1. Project Configuration
# config.yml
baseURL: "https://mon-site.com/"
languageCode: "fr-fr"
title: "Mon Site Hugo"
2. GitHub Actions Workflow
# .github/workflows/hugo.yml
name: Deploy Hugo site to Pages
on:
push:
branches: ["main"]
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: true
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: recursive
fetch-depth: 0
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: 'latest'
extended: true
- name: Build with Hugo
run: hugo --minify
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
with:
path: ./public
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
Best Practices
-
Configuration
- Environment variables
- GitHub secrets
- Dependency caching
- Automated testing
-
Performance
- Optimized builds
- Minified assets
- Effective caching
- Monitoring
-
Security
- Secure tokens
- Minimal permissions
- Input validation
- Regular updates
Conclusion
Key takeaways:
- Automated deployment
- Tailored configuration
- Optimized performance
- Strengthened security
Recommendations:
- Choose the right workflow
- Automate your tests
- Secure your processes
- Follow best practices
- Train yourself on GitHub Actions
About InSkillCoach
Training and technology expert
Coach specializing in advanced technologies and AI, backed by GNeurone Inc.
Certifications:
- AWS Certified Solutions Architect – Professional
- Google Cloud certifications
- Microsoft Certified: DevOps Engineer Expert
- Certified Kubernetes Administrator (CKA)
- CompTIA Security+
695
69
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion