diff --git a/.github/workflows/OATutor-Content-Update b/.github/workflows/OATutor-Content-Update new file mode 100644 index 00000000000..6f8e652adf4 --- /dev/null +++ b/.github/workflows/OATutor-Content-Update @@ -0,0 +1,132 @@ +name: Automated Content Update + +on: + workflow_dispatch: + +jobs: + update-content: + runs-on: ubuntu-latest + + steps: + - name: Checkout OATutor repository + uses: actions/checkout@v2 + with: + ref: 'content-staging' + path: 'content-staging-build' + persist-credentials: true + + - name: Clone OATutor-Tooling repository + run: git clone https://github.com/CAHLR/OATutor-Tooling.git /home/runner/work/OATutor-Tooling + + - name: Install distutils and build tools + run: | + sudo apt-get update + sudo apt-get install -y python3-distutils build-essential meson ninja-build python3-dev + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.11' + + - name: Upgrade pip and install Python dependencies + run: | + pip install --upgrade pip + pip install --prefer-binary -r /home/runner/work/OATutor-Tooling/content_script/requirements.txt + + - name: Create credentials JSON file + run: echo "${{ secrets.OATUTOR_JSON_KEY }}" | base64 --decode > /home/runner/work/oatutor-askoski-705644bfdf34.json + + - name: Set environment variable for spreadsheet key + run: echo "URL_SPREADSHEET_KEY=${{ secrets.URL_SPREADSHEET_KEY }}" >> $GITHUB_ENV + + - name: Remove existing content + run: rm -rf content-staging-build/src/content-sources/oatutor/* + + - name: Create Content Directory + run: mkdir -p content-staging-build/src/content-sources/oatutor/Content + + - name: Clone OATutor-Content repository + uses: actions/checkout@v3 + with: + repository: 'CAHLR/OATutor-Content' + ref: 'main' + token: ${{ secrets.CONTENT_STAGING_PAT }} + path: 'oatutor-content-repo' + + - name: Run content update script + run: | + cd content-staging-build/src/content-sources/oatutor/Content + python3 /home/runner/work/OATutor-Tooling/content_script/final.py online full + + - name: Move generated content to OATutor-Content repository + run: | + rsync -av content-staging-build/src/content-sources/oatutor/Content/ oatutor-content-repo/ + + - name: Configure Git for OATutor-Content + run: | + cd oatutor-content-repo + git config user.email "generic@example.com" + git config user.name "Generic User" + + - name: Commit and push changes to OATutor-Content repository + run: | + cd oatutor-content-repo + git add . + if git diff-index --quiet HEAD; then + echo "No changes to commit" + else + git commit -m "Automated content update" + git push origin main + fi + env: + GITHUB_TOKEN: ${{ secrets.CONTENT_STAGING_PAT }} + + - name: Change homepage in package.json + run: | + cd content-staging-build + sed -i 's/place-holder/OATutor-Content-Staging/g' package.json + + - name: Run CI install + run: | + cd content-staging-build + npm ci + + - name: Run build + run: | + cd content-staging-build + npm run build + env: + REACT_APP_FIREBASE_CONFIG: ${{ secrets.STAGING_FIREBASE_CONFIG }} + CI: false + REACT_APP_BUILD_TYPE: "content-staging" + REACT_APP_MIDDLEWARE_URL: ${{ secrets.STAGING_MIDDLEWARE_URL }} + REACT_APP_COMMIT_HASH: ${{ github.sha }} + REACT_APP_BUILD_TIMESTAMP: ${{ env.build_timestamp }} + + - name: Checkout Content Staging + uses: actions/checkout@v3 + with: + repository: 'CAHLR/OATutor-Content-Staging' + ref: 'main' + token: ${{ secrets.CONTENT_STAGING_PAT }} + path: 'content-staging-deploy' + + - name: Save original git author and git email + run: | + echo "git_email=$(git log --format='%ae' HEAD^!)" >> $GITHUB_ENV + echo "git_name=$(git log --format='%an' HEAD^!)" >> $GITHUB_ENV + + - name: Push changes to Content Staging + run: | + cd content-staging-deploy + git rm -rf . + git clean -fxd + rsync -av ../content-staging-build/build/ . + git add . + git config --global user.email "${{ env.git_email || 'oatutor@example.com' }}" + git config --global user.name "${{ env.git_name || 'OATutor' }}" + git diff --cached --quiet --exit-code && echo "no changes to platform, exiting early" && exit 0 + git commit -m "deploy commit: CAHLR/OATutor@$GITHUB_SHA" + git push + env: + GITHUB_TOKEN: ${{ secrets.CONTENT_STAGING_PAT }}