Skip to content

Commit

Permalink
convert to action
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlancaster committed Nov 13, 2024
1 parent 5a08051 commit 8dc9b99
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 53 deletions.
86 changes: 40 additions & 46 deletions .github/actions/update_citations.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,45 @@
name: Update citation files
description: "Update citation files"
inputs:
CITATION_DIR:
description: 'Directory for citations'
required: true
default: 'src/PyPop/citation'
INIT_FILE:
description: 'Path to the init file'
required: true
default: 'src/PyPop/__init__.py'

on:
workflow_call: # This allows the workflow to be triggered by another workflow
inputs:
CITATION_DIR:
#description: 'Directory for citations'
required: true
default: 'src/PyPop/citation'
type: string
INIT_FILE:
#description: 'Path to the init file'
required: true
default: 'src/PyPop/__init__.py'
type: string
runs:
using: "composite"
steps:
- name: Extract citation formats
id: extract_formats
run: |
python -c '
import ast
with open("${{ inputs.INIT_FILE }}") as f:
contents = f.read()
citation_output_formats = next((node.value.elts for node in ast.walk(ast.parse(contents)) if isinstance(node, ast.Assign) and node.targets[0].id == "citation_output_formats"), [])
formats = ",".join([str(elem.value) for elem in citation_output_formats])
with open("${{ steps.extract_formats.outputs.formats_file }}", "w") as f:
f.write(formats)
'
jobs:
do-citation-updates:
runs-on: ubuntu-latest

steps:
- name: Extract citation formats
id: extract_formats
run: |
python -c '
import ast
with open("${{ inputs.INIT_FILE }}") as f:
contents = f.read()
citation_output_formats = next((node.value.elts for node in ast.walk(ast.parse(contents)) if isinstance(node, ast.Assign) and node.targets[0].id == "citation_output_formats"), [])
formats = ",".join([str(elem.value) for elem in citation_output_formats])
with open("${{ steps.extract_formats.outputs.formats_file }}", "w") as f:
f.write(formats)
'
- name: Copy CITATION.cff to citation directory
run: |
cp CITATION.cff ${{ inputs.CITATION_DIR }}/CITATION.cff
- name: Copy CITATION.cff to citation directory
run: |
cp CITATION.cff ${{ inputs.CITATION_DIR }}/CITATION.cff
- name: Generate citation files
run: |
formats="${{ steps.extract_formats.outputs.formats }}"
IFS=',' read -r -a formats_array <<< "$formats"
for format in "${formats_array[@]}"; do
cffconvert --infile CITATION.cff --outfile "${{ inputs.CITATION_DIR }}/citation.${format}" --format "$format"
done
- name: Generate citation files
run: |
formats="${{ steps.extract_formats.outputs.formats }}"
IFS=',' read -r -a formats_array <<< "$formats"
for format in "${formats_array[@]}"; do
cffconvert --infile CITATION.cff --outfile "${{ inputs.CITATION_DIR }}/citation.${format}" --format "$format"
done
- name: Commit and push changes
uses: EndBug/add-and-commit@v9
with:
message: "Auto-update citation files based on CITATION.cff"
add: "${{ inputs.CITATION_DIR }}/*"
- name: Commit and push changes
uses: EndBug/add-and-commit@v9
with:
message: "Auto-update citation files based on CITATION.cff"
add: "${{ inputs.CITATION_DIR }}/*"
12 changes: 5 additions & 7 deletions .github/workflows/run_citations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,9 @@ jobs:
# use customized version of cffconvert
pip install git+https://github.com/alexlancaster/cffconvert.git@combine_features#egg=cffconvert
call-citation-workflow:
needs: update-citations
uses: ./.github/workflows/update_citations.yml
with:
CITATION_DIR: 'src/PyPop/citation'
INIT_FILE: 'src/PyPop/__init__.py'
secrets: inherit # if any secrets need to be inherited from the calling workflow
- name: Runs composite action
uses: ./.github/actions/update_citations.yml
with:
CITATION_DIR: 'src/PyPop/citation'
INIT_FILE: 'src/PyPop/__init__.py'

0 comments on commit 8dc9b99

Please sign in to comment.