Content Updater #302
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: Content Updater | |
on: | |
workflow_dispatch: | |
schedule: | |
# every day, 4 AM PST | |
- cron: "0 12 * * *" | |
jobs: | |
check-for-update: | |
name: Check for Update | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout static-frame-www | |
uses: actions/checkout@v3 | |
with: | |
repository: ${{ github.repository }} | |
fetch-depth: 0 | |
- name: Collect versions, fail if no updated needed | |
run: | | |
export VERSION_SF_PYPI=$(curl -s https://pypi.org/pypi/static-frame/json | jq -r '.info.version') | |
echo "version pypi: $VERSION_SF_PYPI" | |
export VERSION_SF_CURRENT=$(jq -r '.version' site-static-frame/src/sf-api/metadata.json) | |
echo "version current: $VERSION_SF_CURRENT" | |
if [ "$VERSION_SF_PYPI" == "$VERSION_SF_CURRENT" ]; then | |
echo "update needed: no" | |
exit 1 | |
else | |
echo "update needed: yes" | |
fi | |
update-rtd: | |
name: Update Read the Docs | |
needs: [check-for-update] | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Trigger RTD Latest Builds | |
run: | | |
curl -X POST \ | |
-H "Authorization: Token ${{ secrets.RTD_TOKEN }}" \ | |
-H "Content-Type: application/json" \ | |
"https://readthedocs.org/api/v3/projects/static-frame/versions/latest/builds/" | |
update-site-content: | |
name: Update Site Content | |
needs: [check-for-update] | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout static-frame-www | |
uses: actions/checkout@v3 | |
with: | |
repository: ${{ github.repository }} | |
fetch-depth: 0 | |
- name: Checkout static-frame | |
uses: actions/checkout@v3 | |
with: | |
repository: 'static-frame/static-frame' | |
path: 'static-frame' # this is inside the static-frame-www repo | |
- uses: actions/setup-python@master | |
with: | |
python-version: '3.11' | |
- name: Build JSON files | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements-test-3_11.txt | |
export PYTHONPATH="${PYTHONPATH}:." | |
python3 doc/build_json.py --write --output ../site-static-frame/src/sf-api | |
working-directory: static-frame | |
- name: Remove static-frame | |
run: rm -rf static-frame | |
- name: Extract New Version | |
run: | | |
export VERSION_SF_SOURCED=$(jq -r '.version' site-static-frame/src/sf-api/metadata.json) | |
echo "VERSION_SF_SOURCED=$VERSION_SF_SOURCED" >> $GITHUB_ENV | |
export NAME_BRANCH="content-update-${VERSION_SF_SOURCED}-${GITHUB_RUN_ID}" | |
echo "NAME_BRANCH=$NAME_BRANCH" >> $GITHUB_ENV | |
- name: Commit to Git | |
run: | | |
git diff --stat | |
git config user.email "[email protected]" | |
git config user.name "Content Update Bot" | |
git checkout -b "${NAME_BRANCH}" | |
git commit -m "${NAME_BRANCH}" -a | |
git push origin ${NAME_BRANCH} | |
- name: Create Pull Request | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
PR_DATA=$(jq -n \ | |
--arg title "Content Update ${VERSION_SF_SOURCED} (${GITHUB_RUN_ID})" \ | |
--arg body "--" \ | |
--arg head "${NAME_BRANCH}" \ | |
--arg base "main" \ | |
--argjson assignees '["flexatone"]' \ | |
'{"title": $title, "body": $body, "head": $head, "base": $base}') | |
curl --location --request POST "https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls" \ | |
--header "Authorization: token ${GITHUB_TOKEN}" \ | |
--header "Content-Type: application/json" \ | |
--data "$PR_DATA" | |