Skip to content

Workflow file for this run

name: csv-to-csvw action
description: Generate CSV-W from csv upload to repository.
author: Connected Open Government Statistics (COGS)
branding:
icon: box
color: white
inputs:
commit-outputs-to-branch:
description: Boolean indicating whether the outputs (i.e. out folder) should be committed to the current branch (default is true).
default: true
required: false
publish-to-gh-pages:
description: Boolean indicating whether the outputs (i.e. out folder) should be published to the gh-pages branch and GitHub Pages (default is true).
default: true
required: false
paths-to-exclude:
description: File paths which csv-to-csvw should avoid converting into CSV-Ws
default: ""
required: false
config-required:
description: "(WARNING: Advanced Configuration) Only convert CSV files which have a companion JSON configuration file into CSV-Ws."
default: true
required: true
debug:
description: "(WARNING: Advanced Configuration) Whether to output debug statements in order to help diagnose a fault or unexpected behaviour."
default: false
required: false
runs:
using: composite
steps:
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install csvcubed
run: pip install csvcubed
shell: bash
- name: Verify csvcubed installation
run: csvcubed version
shell: bash
- name: Check out repository
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: View working directory
run: ls -la $GITHUB_WORKSPACE
shell: bash
- name: Set GITHUB_PATH to Action's Repository
# Ensures that scripts we run are resolved relative to the action's repository.
run: echo "${{ github.action_path }}" >> $GITHUB_PATH
shell: bash
- name: Configure git
run: |
git config --global user.name "CSV-W from csv upload generator"
git pull
shell: bash
- name: Update gh-pages and clear branch
if: ${{ fromJSON(inputs.publish-to-gh-pages) == true }}
run: |
git checkout gh-pages || git checkout -b gh-pages
git pull
git checkout "$GITHUB_REF_NAME"
shell: bash
- name: Get added/modified/removed files
id: get-added-changed-removed-files
uses: jitterbit/get-changed-files@v1
with:
format: "csv"
- name: Build and inspect files
id: build-and-inspect-files
env:
FILES_ADDED_MODIFIED: ${{ steps.get-added-changed-removed-files.outputs.added_modified }}
FILES_RENAMED: ${{ steps.get-added-changed-removed-files.outputs.renamed }}
PATHS_TO_EXCLUDE_IN: ${{ inputs.paths-to-exclude }}
JSON_CONFIG_REQUIRED: ${{ inputs.config-required }}
COMMIT_OUTPUTS_TO_GH_PAGES: ${{ fromJSON(inputs.commit-outputs-to-branch) }}
DEBUG: ${{ fromJSON(inputs.debug) == true }}
run: build-and-inspect-files.sh
shell: bash
- name: Handle deleted files
id: process-deleted-files
env:
FILES_REMOVED: ${{ steps.get-added-changed-removed-files.outputs.removed }}
JSON_CONFIG_REQUIRED: ${{ inputs.config-required }}
COMMIT_OUTPUTS_TO_GH_PAGES: ${{ fromJSON(inputs.commit-outputs-to-branch) }}
DEBUG: ${{ fromJSON(inputs.debug) == true }}
run: process-deleted-files.sh
shell: bash
- name: Publish CSV-Ws and logs to artefacts
if: ${{ fromJSON(steps.build-and-inspect-files.outputs.has_outputs) == true }}
uses: actions/upload-artifact@v2
with:
name: assets-for-download
path: out
- name: Commit generated CSV-Ws and logs to the repository
if: ${{ (fromJSON(steps.build-and-inspect-files.outputs.has_outputs) == true || fromJSON(steps.process-deleted-files.outputs.has_outputs)) && (fromJSON(inputs.commit-outputs-to-branch) == true) }}
run: |
echo "--Commiting Outputs to Main Branch"
if [[ -d "$RUNNER_TEMP/out" ]]
then
cp -r "$RUNNER_TEMP/out" .
fi
git add out/
git commit -m "CSV-W Updates - $(date +'%d-%m-%Y at %H:%M:%S')"
git push
shell: bash
- name: Publish CSV-Ws and logs to GitHub Pages
if: ${{ (fromJSON(steps.build-and-inspect-files.outputs.has_outputs) || fromJSON(steps.process-deleted-files.outputs.has_outputs)) && (fromJSON(inputs.publish-to-gh-pages) == true) }}
env:
DEBUG: ${{ fromJSON(inputs.debug) == true }}
run: publish-csvws-to-github-pages.sh
shell: bash