-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: refactored build and deploy workflow, added bibtex prettifier
- Loading branch information
1 parent
74d715e
commit b6cfb13
Showing
3 changed files
with
156 additions
and
41 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
name: Build LaTeX and deploy on GitHub Releases | ||
on: | ||
push: | ||
tags: '*' | ||
branches-ignore: | ||
- 'autodelivery**' | ||
- 'bump-**' | ||
- 'renovate/**' | ||
paths-ignore: | ||
- 'README.md' | ||
- 'CHANGELOG.md' | ||
- 'LICENSE' | ||
- 'renovate.json' | ||
schedule: | ||
- cron: '0 0 * * 0' | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
permissions: { } | ||
|
||
env: | ||
PAPER_BASE_NAME: phd-thesis | ||
|
||
jobs: | ||
success: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: 3.0 | ||
|
||
- name: Install dependencies | ||
run: | | ||
gem install bibtex-ruby | ||
- name: Generate bibliography | ||
run: | | ||
ruby bibtex_prettifier.rb | ||
- name: Compile LaTeX | ||
uses: xu-cheng/latex-action@v3 | ||
with: | ||
root_file: ${{ env.PAPER_BASE_NAME }}.tex | ||
args: -pdf -file-line-error -halt-on-error -interaction=nonstopmode -shell-escape | ||
|
||
- name: Bump version | ||
id: bump-version | ||
uses: anothrNick/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
DRY_RUN: true | ||
|
||
- name: Get Time | ||
id: current-time | ||
run: echo "::set-output name=time::$(date +'%Y-%m-%dT%H%M%S')" | ||
|
||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: '${{ steps.bump-version.outputs.new_tag }}-${{ steps.current-time.outputs.time }}' | ||
release_name: Release '${{ steps.bump-version.outputs.new_tag }}-${{ steps.current-time.outputs.time }}' | ||
|
||
- name: Upload Release Asset | ||
id: upload-release-asset-cv | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: ./${{ env.PAPER_BASE_NAME }}.pdf | ||
asset_name: ${{ env.PAPER_BASE_NAME }}.pdf | ||
asset_content_type: application/pdf |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
require 'bibtex' | ||
|
||
# Separate acronym definitions from actual references | ||
def separate_acronyms(bib) | ||
acronyms = BibTeX::Bibliography.new | ||
references = BibTeX::Bibliography.new | ||
|
||
bib.each do |entry| | ||
# Check if the entry is an acronym definition, e.g., using '@string' | ||
if entry.type.to_s.downcase == 'string' || entry.type.to_s.downcase == 'acronym' | ||
acronyms << entry | ||
else | ||
references << entry | ||
end | ||
end | ||
|
||
return acronyms, references | ||
end | ||
|
||
# Remove 'url' if 'doi' is present | ||
def remove_redundant_url(bib) | ||
bib.each do |entry| | ||
next unless entry.is_a?(BibTeX::Entry) | ||
|
||
if entry.has_field?('doi') && entry.has_field?('url') | ||
entry.delete('url') | ||
end | ||
end | ||
end | ||
|
||
# Remove duplicates by comparing relevant fields and unique identifiers | ||
def remove_duplicates(bib) | ||
seen_entries = {} | ||
unique_entries = BibTeX::Bibliography.new | ||
|
||
bib.each do |entry| | ||
# Ensure the entry is a BibTeX::Entry object | ||
next unless entry.is_a?(BibTeX::Entry) | ||
|
||
# Generate a unique key based on relevant fields (e.g., title, doi, author) | ||
key_fields = ['title', 'doi', 'isbn', 'issn', 'author'] | ||
|
||
# Build a unique identifier for each entry by checking all possible fields | ||
key = key_fields.map { |field| entry[field].to_s if entry.has_field?(field) }.compact.join('|') | ||
|
||
# Only add the entry if it hasn't been seen before | ||
unless seen_entries[key] | ||
seen_entries[key] = true | ||
unique_entries << entry | ||
end | ||
end | ||
|
||
# Return the new bibliography with unique entries | ||
unique_entries | ||
end | ||
|
||
# Load BibTeX file | ||
bibfile = "phd-thesis.bib" | ||
bib = BibTeX.open(bibfile) | ||
|
||
# Separate acronym definitions from actual references | ||
acronyms, references = separate_acronyms(bib) | ||
|
||
# Clean the bibliography (remove duplicates and redundant URLs) | ||
references = remove_duplicates(references) | ||
remove_redundant_url(references) | ||
|
||
# Overwrite the original file with acronyms followed by cleaned references | ||
output_file = "phd-thesis.bib" | ||
File.open(output_file, 'w') do |f| | ||
f.write(acronyms.to_s) # Write the acronym definitions first | ||
f.write(references.to_s) # Write the cleaned references | ||
end | ||
|
||
puts "BibTeX file #{output_file} has been updated" |