From a22db815f31860c19929865be0e56f3dc126bef1 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Fri, 27 Dec 2024 00:43:58 -0800 Subject: [PATCH] Improve GitHub Actions CI workflow for cloudflare-ufw-updater 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. --- .github/workflows/test.yml | 56 ++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3015f8c..936f6bc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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