explicit upstream #10
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: Update JSON API (recurring job) | |
on: | |
push: | |
branches: | |
- master | |
pull_request: | |
branches: | |
- master | |
schedule: | |
- cron: '0 0 * * *' # Runs every day at midnight | |
workflow_dispatch: | |
jobs: | |
update-api: | |
defaults: | |
run: | |
shell: bash -l {0} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: conda-incubator/setup-miniconda@v2 | |
with: | |
python-version: "3.10" | |
mamba-version: "*" | |
channels: conda-forge,alchem0x2a,defaults | |
channel-priority: true | |
activate-environment: sparc-api-test | |
- name: Install package | |
run: | | |
pip install -e ".[test]" | |
- name: Generate json api from github master | |
run: | | |
python -m sparc.docparser --git --include-subdirs | |
- name: Env variable for api version | |
run: | | |
python -c "from sparc.api import SparcAPI; import os; ver=SparcAPI('parameters.json').sparc_version; os.system(f'echo API_VERSION={ver} >> $GITHUB_ENV')" | |
- name: Test if json api is newer than current | |
id: probe | |
run: | | |
echo "UPDATE_NEEDED=false" >> $GITHUB_ENV | |
python .github/workflows/api_version_probe.py || echo "UPDATE_NEEDED=true" >> $GITHUB_ENV | |
continue-on-error: true | |
- name: Create Pull Request | |
if: ${{ env.UPDATE_NEEDED }} == 'true' | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "Github Action Bot" | |
echo "New version is ${API_VERSION}" | |
git checkout -b api_version | |
mv parameters.json sparc/sparc_json_api/ | |
git add sparc/sparc_json_api/parameters.json | |
git commit -m "Add new json api version ${API_VERSION}" | |
git push --set-upstream origin api_version | |
gh pr create --base master --title "[PR Bot] New JSON API version ${API_VERSION}" --body "Merge new JSON API version ${API_VERSION} into master" -R alchem0x2a/SPARC-X-API | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# - name: Create badges | |
# run: | | |
# mkdir -p badges/ | |
# # A coverage test badge | |
# anybadge --value=$COVPERCENT --file=badges/coverage.svg coverage | |
# # A version badge | |
# PIPVER=`pip show sparc-x-api | grep Version | cut -d ' ' -f2` | |
# anybadge --value=$PIPVER --file=badges/package.svg -l sparc-x-api | |
# - name: Manually add git badges | |
# run: | | |
# # Assuming a badges branch already exists! | |
# rm -rf /tmp/*.svg && cp badges/*.svg /tmp/ | |
# git fetch | |
# git switch badges || { echo "Could not check out badges branch. Have you created it on remote?"; exit 1; } | |
# git pull | |
# cp /tmp/*.svg badges/ && git add -f badges/*.svg && rm -rf /tmp/*.svg | |
# git config --global user.email "[email protected]" | |
# git config --global user.name "Github Action Bot (badges only)" | |
# git commit -m "Update badges from run ${RID}" || true | |
# git push -u origin badges || true | |
# env: | |
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# RID: ${{ github.run_id }} | |