Last active
March 8, 2025 15:03
-
-
Save soham2008xyz/310b18005b5ddbb268de9b7a5e881ff3 to your computer and use it in GitHub Desktop.
GitHub CI/CD scripts for popular frameworks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Live Channel | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy_live_website: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- uses: FirebaseExtended/action-hosting-deploy@v0 | |
with: | |
repoToken: "${{ secrets.GITHUB_TOKEN }}" | |
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}" | |
projectId: "${{ secrets.FIREBASE_PROJECT_ID }}" | |
channelId: live |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy | |
on: | |
push: | |
branches: | |
- main | |
env: | |
CI: false | |
NODE_OPTIONS: '--max-old-space-size=8192' | |
jobs: | |
build: | |
name: Build and Deploy | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Cache dependencies | |
uses: actions/cache@v4 | |
with: | |
# See here for caching with `yarn`: https://github.com/actions/cache/blob/main/examples.md#node---yarn | |
# Or you can leverage caching with `actions/setup-node`: https://github.com/actions/setup-node | |
path: | | |
~/.npm | |
${{ github.workspace }}/.next/cache | |
# Generate a new cache whenever packages or source files change. | |
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }} | |
# If source files changed but packages didn't, rebuild from a prior cache. | |
restore-keys: | | |
${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}- | |
- name: Install dependencies | |
run: npm ci | |
- name: Build project | |
run: npm run build | |
- name: Enable Firebase experiments | |
run: npx firebase-tools@latest experiments:enable webframeworks | |
- name: Deploy to Firebase | |
uses: FirebaseExtended/action-hosting-deploy@v0 | |
with: | |
repoToken: "${{ secrets.GITHUB_TOKEN }}" | |
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}" | |
projectId: "${{ secrets.FIREBASE_PROJECT_ID }}" | |
channelId: live |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Server | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Setup SSH | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }} | |
run: | | |
mkdir -p ~/.ssh | |
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
# ssh-keyscan -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts | |
echo "$SSH_KNOWN_HOSTS" >> ~/.ssh/known_hosts | |
- name: Sync files to server | |
env: | |
SSH_USER: ${{ secrets.SSH_USER }} | |
SSH_HOST: ${{ secrets.SSH_HOST }} | |
WORKDIR: ${{ secrets.WORKDIR }} | |
run: | | |
rsync -avz --delete --exclude '.git/' --exclude '.github/' --exclude 'uploads/' --exclude '.gitignore' -e "ssh -i ~/.ssh/id_rsa" ./ $SSH_USER@$SSH_HOST:$WORKDIR | |
- name: Set file permissions | |
env: | |
SSH_USER: ${{ secrets.SSH_USER }} | |
SSH_HOST: ${{ secrets.SSH_HOST }} | |
WORKDIR: ${{ secrets.WORKDIR }} | |
SERVER_USER: ${{ secrets.SERVER_USER }} | |
SERVER_GROUP: ${{ secrets.SERVER_GROUP }} | |
run: | | |
ssh -i ~/.ssh/id_rsa $SSH_USER@$SSH_HOST << EOF | |
sudo find $WORKDIR -type d -exec chmod 775 {} \; | |
sudo find $WORKDIR -type f -exec chmod 664 {} \; | |
sudo chown -R $SERVER_USER:$SERVER_GROUP $WORKDIR | |
EOF | |
- name: Run Composer if needed | |
if: ${{ hashFiles('composer.json') != '' }} | |
env: | |
SSH_USER: ${{ secrets.SSH_USER }} | |
SSH_HOST: ${{ secrets.SSH_HOST }} | |
WORKDIR: ${{ secrets.WORKDIR }} | |
SERVER_USER: ${{ secrets.SERVER_USER }} | |
run: | | |
ssh -i ~/.ssh/id_rsa $SSH_USER@$SSH_HOST << EOF | |
cd $WORKDIR | |
sudo -u $SERVER_USER composer install | |
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy | |
on: | |
push: | |
branches: | |
- main | |
env: | |
NODE_ENV: development | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Install dependencies | |
run: npm ci | |
- name: Build project | |
run: npm run build | |
- name: Upload build files | |
uses: actions/upload-artifact@v4 | |
with: | |
name: production-files | |
path: ./dist | |
deploy: | |
name: Deploy | |
needs: build | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v4 | |
- name: Download build files | |
uses: actions/download-artifact@v4 | |
with: | |
name: production-files | |
path: ./dist | |
- name: Deploy to Firebase | |
uses: FirebaseExtended/action-hosting-deploy@v0 | |
with: | |
repoToken: "${{ secrets.GITHUB_TOKEN }}" | |
firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT }}" | |
projectId: "${{ secrets.FIREBASE_PROJECT_ID }}" | |
channelId: live |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment