Automated Content Update #970
This file contains 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 | |
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 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: 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 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/bktParams1.json | |
cp bkt-params/bktParams1.json bkt-params/bktParams2.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 "Automated 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 }} |