From 5668caaeea09098d013bdb8d1eec5e6a26d2eb61 Mon Sep 17 00:00:00 2001 From: Shengqi Chen Date: Fri, 17 May 2024 12:38:45 +0800 Subject: [PATCH] ci: use actions to deploy github pages, remove obsolete file Signed-off-by: Shengqi Chen --- .build/validator.python2.bak | 107 ----------------------------------- .github/workflows/build.yml | 49 ++++++++-------- 2 files changed, 23 insertions(+), 133 deletions(-) delete mode 100755 .build/validator.python2.bak diff --git a/.build/validator.python2.bak b/.build/validator.python2.bak deleted file mode 100755 index 036ca90..0000000 --- a/.build/validator.python2.bak +++ /dev/null @@ -1,107 +0,0 @@ -#!/usr/bin/env python2 - -from os import sys,path,environ - -environ['LANGUAGE'] = 'en' - -import urllib2 -# OK I know I cannot write python -sys.path.append(path.join(path.dirname(__file__), 'feedvalidator', 'src')) - -from bs4 import BeautifulSoup -import feedvalidator -import socket -socket.setdefaulttimeout(5) - -with open(sys.argv[1], 'r') as opmlFile: - - opml = opmlFile.read().decode('utf-8') - opml = BeautifulSoup(opml, 'xml') - - entries = opml.find_all('outline') - - total = len(entries) - - # Ones that failed the connectivity test - siteFailed = [] - - # Ones that failed the feed validator test - feedCritical = [] - - # Ones that triggered feed validator warnings - feedWarning = [] - - for entry in entries: - title = entry.get('title').encode('utf-8') - print '=== Validating %s ===' % title - - site = entry.get('htmlUrl') - code = -1 - print "Testing HTTP connectivity...: %s" % site - try: - resp = urllib2.urlopen(site) - code = resp.getcode() - except Exception as e: - print "Cannot connect to site: %s" % str(e) - siteFailed.append([title, entry]) - - if code >= 200 and code < 400: - # Is a valid response - print "Site successfully responded with code %s" % code - elif code >= 0: - print "Site responded with unexpected response code %s" % code - siteFailed.append([title, entry]) - - print "Fetching feeds..." - feed = entry.get('xmlUrl') - - events = None - try: - events = feedvalidator.validateURL(feed, firstOccurrenceOnly=1)['loggedEvents'] - except feedvalidator.logging.ValidationFailure as vf: - events = [vf.event] - except Exception as e: - print "Unable to fetch feed: %s" % str(e) - feedCritical.append(e) - - if events is not None: - from feedvalidator import compatibility - from feedvalidator.formatter.text_plain import Formatter - - criticals = compatibility.A(events) - if len(criticals) > 0: - print "Feed failed validation with critical errors:" - output = Formatter(criticals) - print "\n".join(output) - feedCritical.append([title, entry]) - else: - warnings = compatibility.AAA(events) - if len(warnings) > 0: - print "Feed passed validation with warnings:" - output = Formatter(warnings) - print "\n".join(output) - feedWarning.append([title, entry]) - else: - print "Feed passed validation with no error or warning" - - print "" - - print "### SUMMARY ###" - print "In total of %s entries:" % len(entries) - print "%s entries failed the connectivity test:" % len(siteFailed) - for [title, entry] in siteFailed: - print "\t%s: %s" % (title, entry) - print "" - - print "%s entries failed the feed validation:" % len(feedCritical) - for [title, entry] in feedCritical: - print "\t%s: %s" % (title, entry) - print "" - - print "%s entries passed the feed validation with warnings:" % len(feedWarning) - for [title, entry] in feedWarning: - print "\t%s: %s" % (title, entry) - print "" - - if len(feedCritical) > 0: - sys.exit(1) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2fe28f6..3393af4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,19 +1,18 @@ name: 'Build & Validate OPML file' -on: [push] +on: [push, pull_request] jobs: + build: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 with: submodules: recursive - - name: Set up Python 3.10 - uses: actions/setup-python@v5 + - uses: actions/setup-python@v5 with: - python-version: '3.10' + python-version: '3.12' - name: Install dependencies run: | python -m pip install --upgrade pip @@ -24,25 +23,23 @@ jobs: run: | .build/buildOpml.sh > opml.xml .build/validator.py opml.xml || true - - name: Publish Opml + - name: Upload Pages Artifact if: ${{ github.ref == 'refs/heads/master' }} - env: - GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_ACTOR: ${{ github.actor }} - GITHUB_REPO: ${{ github.repository }} - REMOTE_BRANCH: gh-pages - run: | - remote_repo="https://x-access-token:${GITHUB_ACCESS_TOKEN}@github.com/${GITHUB_REPO}.git" - git_commit_id=$(git rev-parse --short HEAD) - mkdir _site_remote && cd _site_remote - git init -b master - git config user.name "${GITHUB_ACTOR}" - git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" - git remote add origin $remote_repo - git pull origin $REMOTE_BRANCH - git rm -rf . - git clean -fxd - cp -a ../opml.xml ./ - git add . - git commit --allow-empty -m "Github Action auto build for https://github.com/${GITHUB_REPO}/commit/${git_commit_id}" - git push -u origin master:$REMOTE_BRANCH + uses: actions/upload-pages-artifact@v3 + with: + path: opml.xml + + deploy: + if: ${{ github.ref == 'refs/heads/master' }} + needs: build + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4