Merge pull request #1 from SINTEF/remove-session #1
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: CI/CD - New updates to 'master' | |
on: | |
push: | |
branches: [master] | |
env: | |
DEPENDABOT_BRANCH: ci/dependabot-updates | |
GIT_USER_NAME: "TEAM 4.0[bot]" | |
GIT_USER_EMAIL: "[email protected]" | |
DEFAULT_REPO_BRANCH: master | |
jobs: | |
update-dependabot-branch: | |
name: Update permanent dependabot branch | |
if: github.repository_owner == 'EMMC-ASBL' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ env.DEPENDABOT_BRANCH }} | |
fetch-depth: 0 | |
- name: Set up git config | |
run: | | |
git config --global user.name "${{ env.GIT_USER_NAME }}" | |
git config --global user.email "${{ env.GIT_USER_EMAIL }}" | |
- name: Update '${{ env.DEPENDABOT_BRANCH }}' | |
run: | | |
git fetch origin | |
LATEST_PR_BODY="$(gh api /repos/${{ github.repository}}/pulls -X GET -f state=closed -f per_page=1 -f sort=updated -f direction=desc --jq '.[].body')" | |
cat .github/utils/single_dependency_pr_body.txt | head -8 > .tmp_file.txt | |
if [ -z "$(printf '%s\n' "${LATEST_PR_BODY}" | head -8 | diff - .tmp_file.txt --strip-trailing-cr)" ]; then | |
# The dependency branch has just been merged into `${{ env.DEFAULT_REPO_BRANCH }}` | |
# The dependency branch should be reset to `${{ env.DEFAULT_REPO_BRANCH }}` | |
echo "The dependencies have just been updated! Reset to ${{ env.DEFAULT_REPO_BRANCH }}." | |
git reset --hard origin/${{ env.DEFAULT_REPO_BRANCH }} | |
echo "FORCE_PUSH=yes" >> $GITHUB_ENV | |
else | |
# Normal procedure: Merge `${{ env.DEFAULT_REPO_BRANCH }}` into `${{ env.DEPENDABOT_BRANCH }}` | |
echo "Merge new updates to ${{ env.DEFAULT_REPO_BRANCH }} into ${{ env.DEPENDABOT_BRANCH }}" | |
git merge -m "Keep '${{ env.DEPENDABOT_BRANCH }}' up-to-date with '${{ env.DEFAULT_REPO_BRANCH }}'" origin/${{ env.DEFAULT_REPO_BRANCH }} | |
echo "FORCE_PUSH=no" >> $GITHUB_ENV | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push to '${{ env.DEPENDABOT_BRANCH }}' | |
uses: CasperWA/push-protected@v2 | |
with: | |
token: ${{ secrets.RELEASE_PAT }} | |
branch: ${{ env.DEPENDABOT_BRANCH }} | |
sleep: 15 | |
force: ${{ env.FORCE_PUSH }} | |
deploy-docs: | |
name: Deploy `latest` documentation | |
if: github.repository_owner == 'EMMC-ASBL' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Release check | |
run: | | |
COMMIT_MSG="$(gh api /repos/${{ github.repository}}/commits/${{ env.DEFAULT_REPO_BRANCH }} --jq '.commit.message')" | |
if [[ "${COMMIT_MSG}" =~ ^Release\ v.*$ ]]; then | |
echo "In a release - do not run this job !" | |
echo "RELEASE_RUN=true" >> $GITHUB_ENV | |
else | |
echo "Not a release - update docs" | |
echo "RELEASE_RUN=false" >> $GITHUB_ENV | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Checkout repository | |
if: env.RELEASE_RUN == 'false' | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python 3.9 | |
if: env.RELEASE_RUN == 'false' | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.9 | |
- name: Install dependencies | |
if: env.RELEASE_RUN == 'false' | |
run: | | |
python -m pip install --upgrade pip | |
pip install -U setuptools wheel | |
pip install -U -e .[docs] | |
- name: Set up git user | |
if: env.RELEASE_RUN == 'false' | |
run: | | |
git config --global user.name "${{ env.GIT_USER_NAME }}" | |
git config --global user.email "${{ env.GIT_USER_EMAIL }}" | |
- name: Check API Reference and landing page | |
if: env.RELEASE_RUN == 'false' | |
run: | | |
pre-commit run --all-files docs-api-reference | |
pre-commit run --all-files docs-landing-page | |
if [ -n "$(git status --porcelain docs/api_reference docs/index.md)" ]; then | |
echo -e "\u274c Discrepancies found !" | |
echo -e "The following files in the documentation must be committed:" | |
git status --porcelain docs/api_reference docs/index.md | |
echo -e "\nRun:\n" | |
echo " pre-commit run --all-files docs-api-reference" | |
echo -e " pre-commit run --all-files docs-landing-page\n" | |
echo "And commit the changed files." | |
exit 1 | |
else | |
echo -e "\u2705 All good !" | |
fi | |
- name: Deploy documentation | |
if: env.RELEASE_RUN == 'false' | |
run: mike deploy --push --remote origin --branch gh-pages --update-aliases --config-file mkdocs.yml latest ${{ env.DEFAULT_REPO_BRANCH }} |