From a00ca29d83f3e7d4b2eb3cfba85ffc410883bdc3 Mon Sep 17 00:00:00 2001 From: Biru Mohanathas Date: Wed, 7 Aug 2024 16:35:06 +0300 Subject: [PATCH] Use actions/upload-pages-artifact to deploy instead of gh-pages branch --- .github/workflows/deploy.yml | 48 ++++++++------------------- .gitignore | 5 +-- _config.yml | 9 +----- build.sh | 28 +--------------- clean.sh | 34 ------------------- deploy.sh | 63 ------------------------------------ package.json | 3 +- 7 files changed, 20 insertions(+), 170 deletions(-) delete mode 100755 clean.sh delete mode 100755 deploy.sh diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2c4677a..a65612c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,4 +1,4 @@ -name: Deploy +name: Deploy Pages on: push: @@ -9,47 +9,27 @@ jobs: deploy: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 + with: + token: ${{ secrets.GITHUB_TOKEN }} + - name: Install Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v4 with: node-version: 20.x - - name: Clone repo - uses: actions/checkout@v1 - - - name: Setup SSH deploy key - run: | - ssh-agent >| ~/.ssh-agent.env - source ~/.ssh-agent.env >| /dev/null - - mkdir -p ~/.ssh - echo "github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" >> ~/.ssh/known_hosts - KEY_FILE=~/.ssh/deploy_key - echo "${DEPLOY_SSH_PRIVATE_KEY}" | base64 --decode > $KEY_FILE - chmod 600 $KEY_FILE - ssh-add $KEY_FILE - env: - DEPLOY_SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_SSH_PRIVATE_KEY }} - shell: bash - - name: Cache node_modules - uses: actions/cache@v1 + uses: actions/cache@v4 with: path: node_modules key: node-modules-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }} - - name: Cache _ghpages.git - uses: actions/cache@v1 - with: - path: _ghpages.git - key: node-modules-${{ runner.os }}-${{ hashFiles('**/deploy.sh') }} - - - name: Deploy + - name: Build run: | - git config --global user.email "deploy@rainmeter.net" - git config --global user.name "Rainmeter Bot" - - npm install - source ~/.ssh-agent.env >| /dev/null - npm run deploy + npm run build shell: bash + + - name: Upload Pages artifact + uses: actions/upload-pages-artifact@v3 + with: + path: ./public diff --git a/.gitignore b/.gitignore index dd2ac68..03f84c0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ *debug.log -_generated +public/ +_generated/ +node_modules/ _ghpages.git .deploy_git db.json -node_modules yarn-error.log diff --git a/_config.yml b/_config.yml index 86da1ee..6747beb 100644 --- a/_config.yml +++ b/_config.yml @@ -12,7 +12,7 @@ permalink_defaults: # Directory source_dir: source -public_dir: _generated +public_dir: public tag_dir: tags archive_dir: archives category_dir: categories @@ -56,10 +56,3 @@ pagination_dir: page # Extensions theme: rainmeter-www - -# Deployment -deploy: - type: git - message: "Update: {{ now('YYYY-MM-DD HH:mm:ss') }}" - repo: https://github.com/rainmeter/rainmeter-www.git - branch: gh-pages \ No newline at end of file diff --git a/build.sh b/build.sh index cd45b5b..1aaecba 100755 --- a/build.sh +++ b/build.sh @@ -4,35 +4,9 @@ set -o errexit set -o pipefail set -o nounset -# init script -PUBLIC_DIR=_generated -GHPAGES_DIR=_ghpages.git SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -YELLOW='\033[1;33m' -WHITE='\033[1;37m' -SET='\033[0m' pushd "$SCRIPT_DIR" -echo -e "${YELLOW}INFO:${WHITE} Starting build script...${SET}" -sleep 1 - -# Clean up old files -echo -e "${YELLOW}1/3:${WHITE} Clean up old files${SET}" -if [ -d "$PUBLIC_DIR" ]; then - rm -rv $PUBLIC_DIR -else - echo -e "INFO $PUBLIC_DIR doesn't exist, continuing..." -fi hexo clean - -# Generate blog -echo -e "${YELLOW}2/3:${WHITE} Generate blog files${SET}" hexo generate - -# Run PostCSS -echo -e "${YELLOW}3/3:${WHITE} Run PostCSS${SET}" -cd $PUBLIC_DIR -postcss css/style.css --replace --verbose - -echo -e "${YELLOW}INFO:${WHITE} Script finished, will close in 5 seconds...${SET}" -sleep 5 \ No newline at end of file +(cd ./public && postcss css/style.css --replace) diff --git a/clean.sh b/clean.sh deleted file mode 100755 index 60cd772..0000000 --- a/clean.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -set -o errexit -set -o pipefail -set -o nounset - -# init script -PUBLIC_DIR=_generated -GHPAGES_DIR=_ghpages.git -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -YELLOW='\033[1;33m' -WHITE='\033[1;37m' -SET='\033[0m' -pushd "$SCRIPT_DIR" - -echo -e "${YELLOW}INFO:${WHITE} Starting build script...${SET}" -sleep 1 - -# Clean up old files -echo -e "${YELLOW}1/1:${WHITE} Clean up old files${SET}" -if [ -d "$PUBLIC_DIR" ]; then - rm -rv $PUBLIC_DIR -else - echo -e "INFO $PUBLIC_DIR doesn't exist, continuing..." -fi -if [ -d "$GHPAGES_DIR" ]; then - rm -rv $GHPAGES_DIR -f -else - echo -e "INFO $GHPAGES_DIR doesn't exist, continuing..." -fi -hexo clean - -echo -e "${YELLOW}INFO:${WHITE} Script finished, will close in 5 seconds...${SET}" -sleep 5 \ No newline at end of file diff --git a/deploy.sh b/deploy.sh deleted file mode 100755 index 3e9de10..0000000 --- a/deploy.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/bin/bash - -set -o errexit -set -o pipefail -set -o nounset - -# init script -PUBLIC_DIR=_generated -GHPAGES_DIR=_ghpages.git -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -YELLOW='\033[1;33m' -WHITE='\033[1;37m' -SET='\033[0m' -pushd "$SCRIPT_DIR" - -echo -e "${YELLOW}INFO:${WHITE} Starting build script...${SET}" -sleep 1 - -# Get old commits from Github repo -echo -e "${YELLOW}1/5:${WHITE} Clone old commits${SET}" -# check if _ghpages.git folder doesn't exist -if [ -d "$GHPAGES_DIR" ]; then - rm -rv $GHPAGES_DIR -f -else - echo -e "INFO $GHPAGES_DIR doesn't exist, continuing..." -fi -git clone --bare -b gh-pages \ - git@github.com:rainmeter/rainmeter-www.git $GHPAGES_DIR - -# Clean up old files -echo -e "${YELLOW}2/5:${WHITE} Clean up old files${SET}" -if [ -d "$PUBLIC_DIR" ]; then - rm -rv $PUBLIC_DIR -else - echo -e "INFO $PUBLIC_DIR doesn't exist, continuing..." -fi -hexo clean - -# Generate blog -echo -e "${YELLOW}3/5:${WHITE} Generate blog files${SET}" -hexo generate - -# Run PostCSS -echo -e "${YELLOW}4/5:${WHITE} Run PostCSS${SET}" -cd $PUBLIC_DIR -postcss css/style.css --replace --verbose - -# Deploy to Github Pages -echo -e "${YELLOW}5/5:${WHITE} Deploy to Github Pages${SET}" -cd $SCRIPT_DIR -export GIT_DIR=$PWD/"$GHPAGES_DIR" -export GIT_WORK_TREE=$PWD/"$PUBLIC_DIR" - -git config core.autocrlf false -git fetch --force origin gh-pages -git reset --mixed FETCH_HEAD -git checkout -- CNAME -git add -A . -git commit -m "Update" -git push origin gh-pages - -echo -e "${YELLOW}INFO:${WHITE} Script finished, will close in 5 seconds...${SET}" -sleep 5 \ No newline at end of file diff --git a/package.json b/package.json index 18654d4..055419c 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,7 @@ "start": "hexo server --log", "generate": "hexo generate", "build": "./build.sh", - "deploy": "./deploy.sh", - "clean": "./clean.sh" + "clean": "hexo clean" }, "dependencies": { "bootstrap": "4.6.2",