-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb5bd01
commit 0eba370
Showing
1 changed file
with
132 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |