Skip to content

UpdateCONTROL

UpdateCONTROL #48

name: UpdateCONTROL
run-name: "UpdateCONTROL"
on:
workflow_dispatch:
inputs:
repo:
description: "The repo in the asterisk org to copy the control data from"
required: true
type: string
workflow_call:
inputs:
repo:
description: |
The repo in the asterisk org to copy the control data from:
required: true
type: string
jobs:
UpdateCONTROL:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
show-progress: false
set-safe-directory: true
- name: checkdata
env:
CONTROL_DIR: ./.github/control
CONTROL_JSON: "${{ inputs.repo }}.json"
CONTROL_ENV: "${{ inputs.repo }}.env"
REPO: ${{ inputs.repo }}
GH_TOKEN: ${{ secrets.ASTERISKTEAM_PAT }}
run: |
echo "Current Directory: $PWD"
echo "Retriving variables from repo $REPO in JSON format"
# gh api --paginate retrieves all results but outputs a
# separate object per 30 entries each with a .variables
# array. The two jq's concat them all into a single array.
gh api /repos/asterisk/${REPO}/actions/variables --paginate \
--jq '.variables' | jq -s 'add' > ${CONTROL_DIR}/${CONTROL_JSON}
# Now convert it to a file that can be sourced as environment variables
echo "Converting ${CONTROL_JSON} to ${CONTROL_ENV}"
jq -r '.[] | "export vars_" + .name + "=" + (.value | @sh)' \
${CONTROL_DIR}/${CONTROL_JSON} > ${CONTROL_DIR}/${CONTROL_ENV}
# Check to see if anything changed
status=$(git status --porcelain)
if [ -z "$status" ] ; then
echo "No changed detected so no update needed"
exit 0
fi
echo "Need to commit new version"
git config --global user.email "[email protected]"
git config --global user.name "Asterisk Development Team"
git pull
git add ${CONTROL_DIR}/${CONTROL_JSON} ${CONTROL_DIR}/${CONTROL_ENV}
git commit -a -m "Update control data for repo ${REPO}"
git push
exit 0