Sort envs returned by REST API by current build's scheduled_on time #50
Workflow file for this run
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: "Generate openapi.json" | |
env: | |
DEFAULT_PYTHON_VERSION: "3.12" | |
on: | |
pull_request: | |
paths: ['conda-store-server/conda_store_server/**'] | |
jobs: | |
update-openapi-json: | |
runs-on: ubuntu-latest | |
# so that we can skip this job by adding 'skip openapi' to the commit message | |
# and only run it when the PR is against the main branch of our repo | |
if: "!contains(github.event.head_commit.message, '[openapi skip]') && github.repository=='conda-incubator/conda-store'" | |
permissions: | |
# Give the default GITHUB_TOKEN write permission to commit and push the | |
# added or changed files to the repository. | |
contents: write | |
defaults: | |
run: | |
shell: bash -el {0} | |
steps: | |
- name: "Checkout repository 🛎️" | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: "Get PR Info" | |
id: pr | |
env: | |
PR_NUMBER: ${{ github.event.issue.number }} | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GH_REPO: ${{ github.repository }} | |
COMMENT_AT: ${{ github.event.comment.created_at }} | |
run: | | |
pr="$(gh api /repos/${GH_REPO}/pulls/${PR_NUMBER})" | |
head_sha="$(echo "$pr" | jq -r .head.sha)" | |
pushed_at="$(echo "$pr" | jq -r .pushed_at)" | |
if [[ $(date -d "$pushed_at" +%s) -gt $(date -d "$COMMENT_AT" +%s) ]]; then | |
echo "Updating is not allowed because the PR was pushed to (at $pushed_at) after the triggering comment was issued (at $COMMENT_AT)" | |
exit 1 | |
fi | |
echo "head_sha=$head_sha" >> $GITHUB_OUTPUT | |
- name: Checkout the branch from the PR that triggered the job | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: gh pr checkout ${{ github.event.issue.number }} | |
- name: Validate the fetched branch HEAD revision | |
env: | |
EXPECTED_SHA: ${{ steps.pr.outputs.head_sha }} | |
run: | | |
actual_sha="$(git rev-parse HEAD)" | |
if [[ "$actual_sha" != "$EXPECTED_SHA" ]]; then | |
echo "The HEAD of the checked out branch ($actual_sha) differs from the HEAD commit available at the time when trigger comment was submitted ($EXPECTED_SHA)" | |
exit 1 | |
fi | |
- name: "Set up Miniconda 🐍" | |
uses: conda-incubator/setup-miniconda@v3 | |
with: | |
environment-file: conda-store-server/environment-dev.yaml | |
- name: "Install conda-store-server 📦" | |
run: python -m pip install conda-store-server/. | |
- name: "Run openapi.json generation script" | |
run: | | |
python docusaurus-docs/scripts/generate_openapi_json.py | |
jq . --sort-keys docusaurus-docs/static/openapi.json > docusaurus-docs/static/openapi.json.formatted | |
mv docusaurus-docs/static/openapi.json.formatted docusaurus-docs/static/openapi.json | |
- name: "Commit changes" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config user.name github-actions[bot] | |
git config user.email github-actions[bot]@users.noreply.github.com | |
git pull --no-tags | |
git add docusaurus-docs/static/openapi.json | |
git commit -m "Update REST API documentation (openapi.json)" | |
git config push.default upstream | |
git push |