110 lines
3.4 KiB
YAML
110 lines
3.4 KiB
YAML
name: Update subject ID mapping for a data ingest pipeline
|
|
description: Generate and publish a partial ID mapping to a destination repository.
|
|
|
|
inputs:
|
|
jwt-audience:
|
|
description: Audience used when fetching the Forgejo JWT to gain access to the destination repository
|
|
required: true
|
|
|
|
destination-repo:
|
|
description: Repository receiving the generated mapping
|
|
required: true
|
|
|
|
destination-file:
|
|
description: Output file name in the destination repository
|
|
required: true
|
|
|
|
columns:
|
|
description: Comma-separated column names for include in the output
|
|
required: true
|
|
|
|
miller-filter:
|
|
description: Optional Miller filter expression applied before selecting columns (see https://miller.readthedocs.io/en/latest/reference-dsl)
|
|
required: false
|
|
default: ""
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Install Miller
|
|
shell: bash
|
|
run: |
|
|
apt-get update -qq
|
|
apt-get install -q --no-install-recommends -y miller
|
|
|
|
- name: Fetch repo update token
|
|
id: jwt
|
|
uses: https://hub.trr379.de/actions/fetch-forgejo-jwt@v1
|
|
with:
|
|
audience: ${{ inputs.jwt-audience }}
|
|
|
|
- name: Set up git-annex
|
|
uses: https://hub.trr379.de/actions/setup-gitannex@v1
|
|
with:
|
|
enable-private-repo-access: "false"
|
|
|
|
- name: Checkout source repo
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Checkout destination repo
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: ${{ inputs.destination-repo }}
|
|
token: ${{ steps.jwt.outputs.jwt }}
|
|
path: target
|
|
|
|
- name: Provision Git(-annex) access token for write access
|
|
uses: https://hub.trr379.de/actions/cache-git-credential@v1
|
|
with:
|
|
repo: target
|
|
password: ${{ steps.jwt.outputs.jwt }}
|
|
|
|
- name: Update repo
|
|
shell: bash
|
|
env:
|
|
MILLER_FILTER: ${{ inputs.miller-filter }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
# We do not want git-annex to record this temporary location.
|
|
git -C target config annex.private true
|
|
git -C target annex init
|
|
|
|
# Remove any previous mapping.
|
|
old_key=$(git -C target annex lookupkey "${{ inputs.destination-file }}" || true)
|
|
rm -f "target/${{ inputs.destination-file }}"
|
|
|
|
# Generate the new mapping in the target location.
|
|
if [[ -n "$MILLER_FILTER" ]]; then
|
|
mlr \
|
|
--itsv \
|
|
--otsv \
|
|
filter "$MILLER_FILTER" \
|
|
then cut -o -f "${{ inputs.columns }}" \
|
|
id.tsv > "target/${{ inputs.destination-file }}"
|
|
else
|
|
mlr \
|
|
--itsv \
|
|
--otsv \
|
|
cut -o -f "${{ inputs.columns }}" \
|
|
id.tsv > "target/${{ inputs.destination-file }}"
|
|
fi
|
|
git -C target annex add "${{ inputs.destination-file }}"
|
|
|
|
# Stop if there is nothing to commit.
|
|
git -C target commit -m "chore: ID mapping update" || exit 0
|
|
|
|
# Deposit the update.
|
|
echo "Deposit update"
|
|
git -C target annex push origin
|
|
git -C target push origin
|
|
|
|
# Drop the previous mapping key from origin if a new one was created.
|
|
echo "Drop previous mapping from destination"
|
|
if [ -n "$old_key" ]; then
|
|
new_key=$(git -C target annex lookupkey "${{ inputs.destination-file }}")
|
|
|
|
if [ "$old_key" != "$new_key" ]; then
|
|
git -C target annex drop --force -f origin --key "$old_key"
|
|
fi
|
|
fi
|