From a98f3b7ed1707e0cb6c138fe2e476fbfa7185a16 Mon Sep 17 00:00:00 2001 From: Rajarshee Chatterjee Date: Sun, 14 Jul 2024 18:28:29 +0530 Subject: [PATCH] chore: Update Workflows [skip ci] --- .github/workflows/prettier.yml | 24 ++++++++ .github/workflows/theme_auto_label.yml | 82 +++++++++++--------------- 2 files changed, 60 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/prettier.yml diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml new file mode 100644 index 0000000..348371e --- /dev/null +++ b/.github/workflows/prettier.yml @@ -0,0 +1,24 @@ +name: Prettier + +on: + pull_request: + branches: [master] + +jobs: + Prettier: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Use Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + + - name: Install Dependencies + run: npm ci + + - name: Prettier + run: npx prettier --check . diff --git a/.github/workflows/theme_auto_label.yml b/.github/workflows/theme_auto_label.yml index 1ff05d3..0452c82 100644 --- a/.github/workflows/theme_auto_label.yml +++ b/.github/workflows/theme_auto_label.yml @@ -1,20 +1,20 @@ -name: Theme auto label +name: Auto Theme Labeler on: issues: types: [labeled] - jobs: auto-label: if: contains(github.event.issue.labels.*.name, 'Source Request') runs-on: ubuntu-latest + env: + REPO: ${{ github.repository }} + ISSUE_NUMBER: ${{ github.event.issue.number }} steps: - - name: Get Source Request URL env: ISSUE_BODY: ${{ github.event.issue.body }} - id: get_url run: | URL=$(echo "$ISSUE_BODY" | sed -n '/### Source link/,+2p' | sed '1,2d' | tr -d '[:space:]') echo "URL=$URL" >> $GITHUB_OUTPUT @@ -23,40 +23,36 @@ jobs: - name: Get User Agent id: get_user_agent run: | - if curl --output chromeVersion.json --silent --fail https://chromiumdash.appspot.com/fetch_releases?channel=Stable\&platform=Windows\&num=1; then - CHROME_VERSION=$(jq -r '.[0].version' chromeVersion.json) - else - CHROME_VERSION=126.0.6478.36 - fi - USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/$CHROME_VERSION Safari/537.36" - echo "USER_AGENT=$USER_AGENT" >> $GITHUB_OUTPUT + CHROME_VERSION=$(curl -s https://chromiumdash.appspot.com/fetch_releases?channel=Stable\&platform=Windows\&num=1 | jq -r '.[0].version // "126.0.6478.36"') + echo "USER_AGENT=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/$CHROME_VERSION Safari/537.36" >> $GITHUB_OUTPUT - - name: Check if URL is valid + - name: Check if URL is Valid id: url_check env: URL: ${{ steps.get_url.outputs.URL }} - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - REPO: ${{ github.repository }} - GITHUB_ISSUE_NUMBER: ${{ github.event.issue.number }} USER_AGENT: ${{ steps.get_user_agent.outputs.USER_AGENT }} run: | if [[ -z "$URL" ]]; then echo "url_valid=false" >> $GITHUB_OUTPUT - echo "# ❌ Error: URL not found" >> $GITHUB_STEP_SUMMARY + echo "❌ Error: URL Not Found" >> $GITHUB_STEP_SUMMARY exit 1 - else - if curl --output /dev/null --silent --head --fail "$URL" -H "User-Agent: $USER_AGENT"; then - echo "url_valid=true" >> $GITHUB_OUTPUT - else - echo "url_valid=false" >> $GITHUB_OUTPUT - echo "# ❌ Error: Request failed" >> $GITHUB_STEP_SUMMARY - echo "URL is invalid or cloudflare issue or site is down" >> $GITHUB_STEP_SUMMARY - gh issue comment $GITHUB_ISSUE_NUMBER -b $'## Warning: Could not check for themes\nThis issue might be because this website has **cloudflare protection**, the URL is invalid or the website is down' -R $REPO - exit 1 - fi fi + if ! curl --output /dev/null --silent --head --fail "$URL" -H "User-Agent: $USER_AGENT"; then + echo "url_valid=false" >> $GITHUB_OUTPUT + echo "❌ Error: Request Failed" >> $GITHUB_STEP_SUMMARY + echo "URL is invalid or cloudflare issue or site is down" >> $GITHUB_ENV + gh issue comment $ISSUE_NUMBER -b ' + > [!WARNING] + > **Unable to Check for Themes** + > This issue may be due to Cloudflare protection on the website, an invalid URL, or the website being down. + + *This message is for development purposes and can be ignored otherwise.* + ' -R $REPO + exit 1 + fi + echo "url_valid=true" >> $GITHUB_OUTPUT - - name: Get base URL + - name: Get Base URL if: steps.url_check.outputs.url_valid == 'true' id: get_base_url env: @@ -64,7 +60,7 @@ jobs: run: | BASE_URL=$(echo "$URL" | sed 's/https\?:\/\///' | cut -d'/' -f1) echo "BASE_URL=$BASE_URL" >> $GITHUB_OUTPUT - echo "Using base URL: \`$BASE_URL\`" >> $GITHUB_STEP_SUMMARY + echo "Using Base URL: \`$BASE_URL\`" >> $GITHUB_STEP_SUMMARY - name: Check Madara theme if: steps.url_check.outputs.url_valid == 'true' @@ -75,15 +71,15 @@ jobs: run: | if curl --location --output /dev/null --silent --head --fail "https://$BASE_URL/wp-content/themes/madara/style.css" -H "User-Agent: $USER_AGENT"; then echo "madara=true" >> $GITHUB_OUTPUT - echo "# ✅ Madara theme found" >> $GITHUB_STEP_SUMMARY + echo "✅ Madara Theme Detected" >> $GITHUB_STEP_SUMMARY elif curl --location --output /dev/null --silent --head --fail "http://$BASE_URL/wp-content/themes/madara/style.css" -H "User-Agent: $USER_AGENT"; then echo "madara=true" >> $GITHUB_OUTPUT - echo "# ✅ Madara theme found" >> $GITHUB_STEP_SUMMARY + echo "✅ Madara Theme Detected" >> $GITHUB_STEP_SUMMARY else echo "madara=false" >> $GITHUB_OUTPUT fi - - name: Check lighnovelwp theme + - name: Check Lighnovelwp theme if: steps.url_check.outputs.url_valid == 'true' id: check_lighnovelwp env: @@ -92,15 +88,15 @@ jobs: run: | if curl --location --output /dev/null --silent --head --fail "https://$BASE_URL/wp-content/themes/lightnovel/style.css" -H "User-Agent: $USER_AGENT"; then echo "lighnovelwp=true" >> $GITHUB_OUTPUT - echo "# ✅ Lighnovelwp theme found" >> $GITHUB_STEP_SUMMARY + echo "✅ Lighnovelwp Theme Detected" >> $GITHUB_STEP_SUMMARY elif curl --location --output /dev/null --silent --head --fail "http://$BASE_URL/wp-content/themes/lightnovel/style.css" -H "User-Agent: $USER_AGENT"; then echo "lighnovelwp=true" >> $GITHUB_OUTPUT - echo "# ✅ Lighnovelwp theme found" >> $GITHUB_STEP_SUMMARY + echo "✅ Lighnovelwp Theme Detected" >> $GITHUB_STEP_SUMMARY else echo "lighnovelwp=false" >> $GITHUB_OUTPUT fi - - name: Check if site has multiple themes + - name: Check if the site has multiple themes if: steps.url_check.outputs.url_valid == 'true' id: check_multiple_themes env: @@ -109,27 +105,21 @@ jobs: run: | if [[ "$MADARA" == "true" && "$LIGHNOVELWP" == "true" ]]; then echo "multiple_themes=true" >> $GITHUB_OUTPUT - echo "# ❌ Error: Site has multiple themes" >> $GITHUB_STEP_SUMMARY + echo "❌ Error: Multiple Themes Detected on Site" >> $GITHUB_STEP_SUMMARY exit 1 - else - echo "multiple_themes=false" >> $GITHUB_OUTPUT fi + echo "multiple_themes=false" >> $GITHUB_OUTPUT - - name: Add label + - name: Add Label if: steps.check_multiple_themes.outputs.multiple_themes == 'false' env: MADARA: ${{ steps.check_madara.outputs.madara }} LIGHNOVELWP: ${{ steps.check_lighnovelwp.outputs.lighnovelwp }} - GITHUB_ISSUE_NUMBER: ${{ github.event.issue.number }} - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - REPO: ${{ github.repository }} run: | - gh label create "Theme: Madara" -d "Site uses Madara theme" -R $REPO || true - gh label create "Theme: Lighnovelwp" -d "Site uses Lighnovelwp theme" -R $REPO || true if [[ "$MADARA" == "true" ]]; then - gh issue edit $GITHUB_ISSUE_NUMBER --add-label "Theme: Madara" -R $REPO + gh issue edit $ISSUE_NUMBER --add-label "Theme: Madara" -R $REPO elif [[ "$LIGHNOVELWP" == "true" ]]; then - gh issue edit $GITHUB_ISSUE_NUMBER --add-label "Theme: Lighnovelwp" -R $REPO + gh issue edit $ISSUE_NUMBER --add-label "Theme: Lighnovelwp" -R $REPO else - echo "## No theme found" >> $GITHUB_STEP_SUMMARY + echo "No Theme Detected" >> $GITHUB_STEP_SUMMARY fi