Generate Zotero to CSL Mappings HTML #9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Generate Zotero to CSL Mappings HTML | |
on: | |
workflow_dispatch: # Manual trigger | |
jobs: | |
generate-html: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install requests jq | |
- name: Fetch the latest schema version | |
id: fetch_version | |
run: | | |
# Fetch the schema JSON from GitHub | |
curl -s https://raw.githubusercontent.com/zotero/zotero-schema/master/schema.json > schema.json | |
# Extract the version from the schema | |
SCHEMA_VERSION=$(jq -r '.version' schema.json) | |
# Output the version | |
echo "Schema version is $SCHEMA_VERSION" | |
# Check if the version has changed by comparing with the stored version | |
if [ -f last_known_version.txt ]; then | |
LAST_KNOWN_VERSION=$(cat last_known_version.txt) | |
echo "Last known version is $LAST_KNOWN_VERSION" | |
else | |
LAST_KNOWN_VERSION="none" | |
echo "No previous version found." | |
fi | |
# Compare versions, proceed only if different | |
if [ "$SCHEMA_VERSION" != "$LAST_KNOWN_VERSION" ]; then | |
echo "New version found, proceed with generating the HTML." | |
echo $SCHEMA_VERSION > last_known_version.txt | |
echo "version_changed=true" >> $GITHUB_ENV # Updated to use environment files | |
else | |
echo "No new version. Skip the process." | |
echo "version_changed=false" >> $GITHUB_ENV # Updated to use environment files | |
fi | |
- name: Generate HTML if version changed | |
if: env.version_changed == 'true' | |
run: | | |
python generate_zot2csl.py # Run your Python script to generate the HTML | |
- name: Commit and push HTML output to repository | |
if: env.version_changed == 'true' | |
run: | | |
# Create a directory for the output HTML file (if it doesn't exist) | |
mkdir -p doc | |
# Move the generated HTML file to the output directory | |
mv index.html docs/index.html | |
# Set up git config for commit | |
git config user.name "github-actions" | |
git config user.email "github-actions@github.com" | |
# Add the output file to git | |
git add docs/index.html | |
# Commit and push the changes | |
git commit -m "Update Zotero to CSL HTML mapping - new schema version" | |
git push | |
- name: Notify if no new version | |
if: env.version_changed == 'false' | |
run: | | |
echo "No new version detected, skipping HTML generation." |