Skip to content

Commit

Permalink
handle errors in CI/CD workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperlarson committed Aug 22, 2024
1 parent e020b00 commit 27a755a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: sudo npm install -g pnpm

- name: Stop the production server
run: sudo systemctl stop portfolio
run: sudo systemctl stop portfolio || echo "Failed to stop the server, continuing..."

- name: Steal ownership of production server directory
run: sudo chown -R gh-runner:gh-runner /srv/portfolio
Expand All @@ -50,6 +50,7 @@ jobs:
run: pnpm build

- name: Publish Executable
if: success()
run: |
sudo find /srv/portfolio/ -mindepth 1 \
! -path '/srv/portfolio/media*' \
Expand All @@ -63,15 +64,22 @@ jobs:
--exclude 'log' --exclude 'tmp' /home/gh-runner/actions-runner/_work/portfolio/portfolio/ /srv/portfolio/
- name: Install deps in prod after copy to be safe
if: success()
run: |
cd /srv/portfolio
pnpm install
- name: Handle failure
if: failure()
run: echo "Build failed, restoring permissions and restarting production server..."

- name: Restore permissions in production directory
if: always()
run: |
sudo chown -R www-data:www-data /srv/portfolio/
sudo chmod -R 755 /srv/portfolio/
sudo chown -R gh-runner:gh-runner /home/gh-runner/
- name: Start production server
if: always()
run: sudo systemctl start portfolio

0 comments on commit 27a755a

Please sign in to comment.