Skip to content

Test Release

Test Release #15

name: Build and Release
on:
release:
types: [created]
permissions:
contents: write
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
# Check out the repository
- name: Check out the code
uses: actions/checkout@v3
# Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20' # Use the Node.js version your project requires
# Install dependencies
- name: Install dependencies
run: |
npm install --global yarn
yarn install
# Build the project
- name: Build the project
run: npm run build
# Zip the project
- name: Build the project
run: zip -r build.zip build/
# Set up the GitHub CLI
- name: Install GitHub CLI
run: sudo apt-get install gh
# Upload files to release
- name: Upload ZIP file to Release
run: gh release upload "${{ github.event.release.tag_name }}" "build.zip" --clobber
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Send to the server
- name: Update the Server Side
uses: appleboy/ssh-action@v1.1.0
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
echo "Downloading build.zip from the latest release..."
curl -L -o build.zip https://github.com/COMSOC-Community/pabuviz-web/releases/latest/download/build.zip
# Verify if the download succeeded
if [ ! -f build.zip ]; then
echo "Error: build.zip was not downloaded. Check the release URL or network."
exit 1
fi
# Ensure the web_old and web directories exist
mkdir -p web_old
mkdir -p web
# Move existing files to backup folder only if files exist
if [ "$(ls -A web)" ]; then
echo "Moving existing files to web_old..."
rm -rf web_old/*
mv web/* web_old/
else
echo "No existing files in web to backup."
fi
# Move and unzip the new build.zip in web directory
echo "Deploying new build.zip..."
mv build.zip web/
cd web/
unzip build.zip && rm build.zip