|
| 1 | +name: Convert Bib to CSL JSON |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - '**/*.bib' |
| 7 | +pull_request: |
| 8 | + paths: |
| 9 | + - '**/*.bib' |
| 10 | +workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + convert_bib_to_csljson: |
| 14 | + runs-on: ubuntu-22.04 |
| 15 | +steps: |
| 16 | + - name: Checkout repository |
| 17 | +uses: actions/checkout@v4 |
| 18 | +with: |
| 19 | + fetch-depth: 0 |
| 20 | + |
| 21 | +- name: Download Google Sheet as CSV |
| 22 | +run: | |
| 23 | + curl -L -o google_sheet.csv "https://docs.google.com/spreadsheets/d/1Px_HAdkRP7z_AyuQCBzuTAolVm5npUFZbbH92o7CsZ4/export?format=csv" |
| 24 | +
|
| 25 | +- name: Extract BibTeX from CSV |
| 26 | +id: extract_bibtex |
| 27 | +run: | |
| 28 | + if [ -f google_sheet.csv ]; then |
| 29 | +bibtex_entries=$(awk -F',' 'NR>1 {print $2}' google_sheet.csv) # Assumes BibTeX is in the SECOND column |
| 30 | +if [ -n "$bibtex_entries" ]; then |
| 31 | +echo "$bibtex_entries" > google_sheet_bibtex.bib |
| 32 | +echo "google_bib=google_sheet_bibtex.bib" >> $GITHUB_OUTPUT |
| 33 | +else |
| 34 | + echo "No BibTeX entries found in the CSV." |
| 35 | +echo "google_bib=" >> $GITHUB_OUTPUT |
| 36 | +fi |
| 37 | +else |
| 38 | + echo "google_sheet.csv not found." |
| 39 | +echo "google_bib=" >> $GITHUB_OUTPUT |
| 40 | +fi |
| 41 | + |
| 42 | +- name: Find .bib files |
| 43 | +id: find_bib_files |
| 44 | +run: | |
| 45 | + bib_files=$(find content data static -name "*.bib" | tr '\n' ' ') |
| 46 | +if [[ -n "${{ steps.extract_bibtex.outputs.google_bib }}" ]]; then |
| 47 | +if [[ -n "$bib_files" ]]; then |
| 48 | +bib_files="$bib_files ${{ steps.extract_bibtex.outputs.google_bib }}" |
| 49 | +else |
| 50 | + bib_files="${{ steps.extract_bibtex.outputs.google_bib }}" |
| 51 | +fi |
| 52 | +fi |
| 53 | +if [[ -z "$bib_files" ]]; then |
| 54 | +echo "No .bib files found." |
| 55 | +echo "bib_files=" >> $GITHUB_OUTPUT |
| 56 | +exit 0 |
| 57 | +fi |
| 58 | +echo "Found .bib files: $bib_files" |
| 59 | +echo "bib_files=$bib_files" >> $GITHUB_OUTPUT |
| 60 | + |
| 61 | +- name: Combine .bib files |
| 62 | +if: steps.find_bib_files.outputs.bib_files |
| 63 | +id: combine_bib |
| 64 | +run: | |
| 65 | + if [[ -z "${{ steps.find_bib_files.outputs.bib_files }}" ]]; then |
| 66 | +exit 0 |
| 67 | +fi |
| 68 | +combined_bib="combined.bib" |
| 69 | +cat ${{ steps.find_bib_files.outputs.bib_files }} > $combined_bib |
| 70 | +echo "Combined .bib files into $combined_bib" |
| 71 | +echo "combined_bib=$combined_bib" >> $GITHUB_OUTPUT |
| 72 | + |
| 73 | +- name: Convert to CSL JSON |
| 74 | +if: steps.find_bib_files.outputs.bib_files |
| 75 | +uses: docker://pandoc/latex:3.5 |
| 76 | +with: |
| 77 | + args: ${{ steps.combine_bib.outputs.combined_bib }} -t csljson -o data/bib.json |
| 78 | + |
| 79 | +- name: Upload CSL JSON Artifact |
| 80 | +if: steps.find_bib_files.outputs.bib_files |
| 81 | +uses: actions/upload-artifact@v4 |
| 82 | +with: |
| 83 | + name: csl-json |
| 84 | +path: data/bib.json |
0 commit comments