Skip to content

Update Moodle WS Structure #48

Update Moodle WS Structure

Update Moodle WS Structure #48

Workflow file for this run

name: Update Moodle WS Structure
on:
workflow_dispatch:
schedule:
- cron: '0 4 * * 1' # Mondays morning.
jobs:
structure:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
moodle_branch: ['master', 'MOODLE_403_STABLE', 'MOODLE_402_STABLE', 'MOODLE_401_STABLE']
env:
dbtype: pgsql
php: 8.1
MOODLE_BRANCH: ${{ matrix.moodle_branch || 'master' }}
MOODLE_REPOSITORY: 'https://github.com/moodle/moodle'
steps:
- name: Checking out code
uses: actions/checkout@v3
- name: Checking out Moodle ${{ env.MOODLE_BRANCH }}
run: |
git clone --branch $MOODLE_BRANCH --depth 1 $MOODLE_REPOSITORY $GITHUB_WORKSPACE/moodle
- name: Setting up DB ${{ env.dbtype }}
uses: m4nu56/postgresql-action@v1
with:
postgresql version: 13
postgresql db: test
postgresql user: test
postgresql password: test
- name: Setting up PHP ${{ env.php }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ env.php }}
ini-values: max_input_vars=5000
coverage: none
- name: Setting up Moodle
env:
dbtype: ${{ env.dbtype }}
run: |
cp structure/config-template.php $GITHUB_WORKSPACE/moodle/config.php
pushd $GITHUB_WORKSPACE/moodle
echo "pathtophp=$(which php)" >> $GITHUB_ENV # Inject installed pathtophp to env. The template config needs it.
mkdir ../moodledata
php admin/cli/install_database.php --agree-license --adminpass=1234 [email protected] --fullname=Structure --shortname=structure --summary=Structure
popd
- name: Run structure script
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git remote set-url origin https://[email protected]/$GITHUB_REPOSITORY.git
git fetch -q origin
echo "Executing PHP script..."
php structure/get_all_ws_structures.php $GITHUB_WORKSPACE/moodle > structure/${{ env.MOODLE_BRANCH }}.ts
git add structure/*.ts
echo "Checking if there are any changes to commit"
if [ -z "$(git diff --cached)" ]; then
echo "No changes detected, exiting"
exit 0
fi
echo "Committing changes"
git commit -m "[auto-generated] Update structure file for ${{ env.MOODLE_BRANCH }}"
echo "Pushing changes"
git pull -r
git push
if [ $? -ne 0 ]; then
echo "Push failed, retrying in ~30 seconds"
sleep $((RANDOM % 30))
git pull -r
git push
fi
echo "Changes pushed successfully"