Skip to content

Commit

Permalink
Auto Deploy CICD (#7)
Browse files Browse the repository at this point in the history
* Add auto-release github CI

* Give write permission to CI to enable release

* Add ci for every push, update auto release name

* fix auto-release cicd tag name

* Fix auto-release CICD, set date-based tag name for release

* Fix CI tag name

* Fix auto-release ci tag name

* Add script for getting latest release

* Modify script for extracting tar.gz static build to target dir
  • Loading branch information
HuakunShen authored Oct 28, 2023
1 parent a9888c8 commit bad7a8b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Auto Release

on:
push:
branches:
- main
- auto-release

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup node env 🏗
uses: actions/setup-node@v3
with:
node-version: 18
check-latest: true
- name: Bun Setup
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: INstall Dependencies
run: bun install
- name: Generate Static Website
run: |
bun generate
mv .output/public static_website
tar -czvf static_website.tar.gz static_website
- name: Set Release Name
id: set_release_name
run: |
echo "RELEASE_NAME=$(date +'%Y-%m-%d %H:%M:%S')" >> "$GITHUB_OUTPUT"
echo "TAG_NAME=v$(date +'%Y-%m-%d-%H-%M-%S')" >> "$GITHUB_OUTPUT"
- name: Create Release
uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.set_release_name.outputs.TAG_NAME }}
release_name: ${{ steps.set_release_name.outputs.RELEASE_NAME }}
draft: false
prerelease: false
- name: upload linux artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./static_website.tar.gz
asset_name: static_website.tar.gz
asset_content_type: application/gzip
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This CI Pipeline is used to make sure the website can be built
name: Build CI

on:
push:
pull_request:
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup node env 🏗
uses: actions/setup-node@v3
with:
node-version: 18
check-latest: true
- name: Bun Setup
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: INstall Dependencies
run: bun install
- name: Generate Static Website
run: bun generate
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ sw.*

# Local Netlify folder
.netlify
static_website.tar.gz
Binary file modified bun.lockb
Binary file not shown.
18 changes: 18 additions & 0 deletions scripts/download_latest_release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# Replace with your GitHub username and repository name
USERNAME="ProSE-uoft-org"
REPO="group-website"
ASSET_NAME="static_website.tar.gz"

# Get the download URL for the asset
DOWNLOAD_URL=$(curl -s "https://api.github.com/repos/$USERNAME/$REPO/releases/latest" | jq -r '.assets[] | select(.name == "'$ASSET_NAME'") | .browser_download_url')
echo $DOWNLOAD_URL
if [ -n "$DOWNLOAD_URL" ]; then
rm $ASSET_NAME
echo "Downloading $ASSET_NAME..."
# Download the asset using curl
curl -LJO -H 'Accept: application/octet-stream' "$DOWNLOAD_URL"
else
echo "Asset $ASSET_NAME not found in the latest release."
fi
7 changes: 7 additions & 0 deletions scripts/extract_to_public_html.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
ASSET_NAME="static_website.tar.gz"
tar -zxvf $ASSET_NAME
# clear ~/public_html
rm -rf ~/public_html/*
# move the contents of the extracted tarball to ~/public_html
mv static_website/* ~/public_html

0 comments on commit bad7a8b

Please sign in to comment.