Skip to content

Commit

Permalink
Improve GitHub Actions CI workflow for cloudflare-ufw-updater
Browse files Browse the repository at this point in the history
Updated workflow to streamline steps and ensure compatibility with the latest GitHub Actions best practices.
-   Replaced  `actions/setup-bash`  with direct dependency setup since the action is not available.
-   Added ShellCheck installation to validate shell scripts.
-   Enhanced test steps with fail-safe mechanisms to handle UFW environment mocking and restoration.
-   Improved readability and robustness by using conditional logic and better error handling.
-   Ensured correct syntax, indentation, and structure for a clean and maintainable YAML file.
  • Loading branch information
thomasvincent authored Dec 27, 2024
1 parent b6d1ea0 commit a22db81
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,42 @@ name: CI

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Bash
uses: actions/setup-bash@v3
- name: Run shellcheck
uses: ludeeus/action-shellcheck@master
with:
severity: error
- name: Run tests
run: |
# Install dependencies (if any)
sudo apt-get update
sudo apt-get install -y ufw curl
# Mock UFW for testing
sudo mv /usr/sbin/ufw /usr/sbin/ufw.real
sudo touch /usr/sbin/ufw
sudo chmod +x /usr/sbin/ufw
# Run the script with test arguments
./cloudflare-ufw-updater.sh
./cloudflare-ufw-updater.sh --restore
# Restore original UFW
sudo mv /usr/sbin/ufw.real /usr/sbin/ufw
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up dependencies
run: |
sudo apt-get update
sudo apt-get install -y ufw curl shellcheck
- name: Run ShellCheck
run: |
shellcheck cloudflare-ufw-updater.sh
- name: Prepare environment for tests
run: |
# Mock UFW for testing
sudo mv /usr/sbin/ufw /usr/sbin/ufw.real || true
sudo touch /usr/sbin/ufw
sudo chmod +x /usr/sbin/ufw
- name: Run tests
run: |
# Run the script with test arguments
./cloudflare-ufw-updater.sh
./cloudflare-ufw-updater.sh --restore
- name: Restore environment
if: always()
run: |
# Restore original UFW
sudo mv /usr/sbin/ufw.real /usr/sbin/ufw || true

0 comments on commit a22db81

Please sign in to comment.