Automated Content Update (Partial) #10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Automated Content Update (Partial) | |
| on: | |
| workflow_dispatch: | |
| schedule: | |
| - cron: '0 3 * * *' | |
| - cron: '0 15 * * *' | |
| 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 -b move-hash-computation-to-python https://github.com/mjyang00001/OATutor-Tooling.git /home/runner/work/OATutor-Tooling | |
| - name: Install distutils and build tools | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y 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: Prepare for incremental update | |
| run: | | |
| cd content-staging-build/src/content-sources/oatutor | |
| # Rename content-pool back to OpenStax Content for the script | |
| if [ -d "content-pool" ]; then | |
| mv "content-pool" "OpenStax Content" | |
| fi | |
| mkdir -p Content | |
| cp bkt-params/defaultBKTParams.json bktParams.json | |
| - 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 | |
| - name: Move and prepare files | |
| run: | | |
| cd content-staging-build/src/content-sources/oatutor | |
| mv "OpenStax Content" "content-pool" | |
| mkdir -p bkt-params | |
| mv bktParams.json bkt-params/defaultBKTParams.json | |
| cp bkt-params/defaultBKTParams.json bkt-params/experimentalBKTParams.json | |
| - name: Run Node.js preprocessing script | |
| run: | | |
| cd content-staging-build/src/tools | |
| node preprocessProblemPool.js | |
| - name: Configure Git | |
| run: | | |
| cd content-staging-build | |
| git config user.email "generic@example.com" | |
| git config user.name "Generic User" | |
| - name: Commit and push changes | |
| run: | | |
| cd content-staging-build | |
| git add . | |
| if git diff-index --quiet HEAD; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "Incremental content update" | |
| git push origin content-staging | |
| 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 | |
| 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 }} |