Skip to content

Commit

Permalink
Merge pull request #18 from neicnordic/feature/aggregate-action
Browse files Browse the repository at this point in the history
Add docs aggregation github action
  • Loading branch information
norling committed Nov 4, 2022
2 parents 31d6f86 + 5e64dc8 commit a83b55b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/aggregate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "Aggregate documentation"

on:
workflow_dispatch:
inputs:
repository:
description: 'Repository to aggregate documentation from'
required: true
default: "neicnordic/sda-pipeline"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: bash aggregate-repositories.sh ${{ inputs.repository }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v4
12 changes: 12 additions & 0 deletions aggregate-mappings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"neicnordic/sda-pipeline": {
"cmd/backup/backup.md": "docs/services/backup.md",
"cmd/finalize/finalize.md": "docs/services/finalize.md",
"cmd/ingest/ingest.md": "docs/services/ingest.md",
"cmd/intercept/intercept.md": "docs/services/intercept.md",
"cmd/mapper/mapper.md": "docs/services/mapper.md",
"cmd/notify/notify.md": "docs/services/notify.md",
"cmd/verify/verify.md": "docs/services/verify.md",
"cmd/pipeline.md": "docs/services/pipeline.md"
}
}
48 changes: 48 additions & 0 deletions aggregate-repositories.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/bash
#
# This script is run in the "Aggregate documentation" github workflow.
#
# The script takes one or more repositories as arguments, clones those
# repositories main branches, and copies files into this repo according to the
# mappings in `aggregate-mappings.json`.
#

set -e

echo "Aggregating files"

for repo in "$@"
do
# clone repo into a temp dir
tempdir="$(mktemp -d)"
git clone "https://github.com/$repo" "$tempdir/${repo#*/}"

# get file mappings from mappings file
repo_mappings=$(jq .["\"$repo\""] < aggregate-mappings.json)
for key in $(jq -r 'keys[]' <<< "$repo_mappings")
do
target=$(jq -r .["\"$key\""] <<< "$repo_mappings")
if [ -f "$tempdir/${repo#*/}/$key" ]
then
cp "$tempdir/${repo#*/}/$key" "$target"
git add "$target"
fi
done

# check if there are any changes
if ! git status | grep 'nothing to commit'
then
# commit files to repo
msg=$(date +"Update from $repo at %H:%M on %Y-%m-%d")

git config --global user.name 'Github aggregate action'
git config --global user.email 'aggregate@users.noreply.github.com'
git commit -m "$msg"
else
echo "No changes to commit"
fi

# clean up temp dir
rm -rf "$tempdir"

done

0 comments on commit a83b55b

Please sign in to comment.