Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reusable workflows #23

Merged
merged 30 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 5 additions & 18 deletions .github/workflows/apply-pip-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
echo "python_version=$(python3 scripts/get_python_version.py)" >> "$GITHUB_OUTPUT"
id: get-python-version
- name: Set up Python
uses: actions/setup-python@v5
- uses: deargen/workflows/actions/apply-pip-compile@master
with:
python-version: ${{ steps.get-python-version.outputs.python_version }}
- name: Install uv
run: |
pip3 install uv
- name: Run uv pip compile and push
run: |
set +e # Do not exit shell on failure
bash scripts/compile_requirements.sh
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git add .
git commit -m "build: update requirements using uv pip compile [skip ci]"
git push
pyproject-toml-file: pyproject.toml
requirements-in-dir: deps
requirements-out-dir: deps/lock
python-platforms: x86_64-unknown-linux-gnu,aarch64-apple-darwin,x86_64-apple-darwin,x86_64-pc-windows-msvc
38 changes: 6 additions & 32 deletions .github/workflows/check-docs.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,15 @@
name: check docs
name: Check mkdocs build

on: pull_request

jobs:
mkdocs:
runs-on: ubuntu-latest
environment: mkdocs

steps:
- uses: actions/checkout@v4
- name: Run mkdocs
run: |
pip3 install uv
uv venv
source .venv/bin/activate
uv pip install -r deps/x86_64-unknown-linux-gnu/requirements_docs.txt

set +e # Do not exit shell on failure

out=$(mkdocs build 2> stderr.txt)
exit_code=$?
err=$(<stderr.txt)

# Display the raw output in the step
echo "${out}"
echo "${err}"

# Display the Markdown output in the job summary
{ echo "\`\`\`python"; echo "${out}"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"

if [[ "${exit_code}" -ne 0 ]]; then
# If the build failed, try to generate the __init__.py file and build again
python scripts/gen_init_py.py
out=$(mkdocs build 2> stderr.txt)
new_exit_code=$?
if [[ "${new_exit_code}" -eq 0 ]]; then
echo "Tip: the build succeeded after generating __init__.py. Try running scripts/gen_init_py.py." >> "$GITHUB_STEP_SUMMARY"
fi
fi
exit ${exit_code}
- name: Check mkdocs
uses: deargen/workflows/actions/check-mkdocs@master
with:
src-dir: src
requirements-docs-file: deps/lock/x86_64-unknown-linux-gnu/requirements_docs.txt
53 changes: 15 additions & 38 deletions .github/workflows/check-pip-compile.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,25 @@
name: Check pip compile sync

on: [push, pull_request]
on:
push:
branches:
- main
- master
pull_request:

concurrency:
group: ${{github.workflow}}-${{github.ref}}
cancel-in-progress: true

jobs:
check-pip-compile:
name: Check pip compile
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
echo "python_version=$(python3 scripts/get_python_version.py)" >> "$GITHUB_OUTPUT"
id: get-python-version
- name: Set up Python
uses: actions/setup-python@v5
- uses: deargen/workflows/actions/check-pip-compile@master
with:
python-version: ${{ steps.get-python-version.outputs.python_version }}
- name: Install uv
run: |
pip3 install uv
- name: Generate lockfile and print diff
run: |
set +e # Do not exit shell on failure

out=$(bash scripts/compile_requirements.sh 2> _stderr.txt)
exit_code=$?
err=$(<_stderr.txt)

if [[ -n "$out" ]]; then
# Display the raw output in the step
echo "${out}"
# Display the Markdown output in the job summary
{ echo "\`\`\`"; echo "${out}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
fi
if [[ -n "$err" ]]; then
echo "${err}"
{ echo "\`\`\`"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
fi

if [[ $exit_code -eq 0 ]]; then
# When the script fails, there are changes in requirements that are not compiled yet.
# Print the suggested changes.
{ echo "\`\`\`diff"; git diff; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"
exit 1
fi

# When the script fails, it means it does not have anything to compile.
exit 0
pyproject-toml-file: pyproject.toml
requirements-in-dir: deps
requirements-out-dir: deps/lock
python-platforms: x86_64-unknown-linux-gnu,aarch64-apple-darwin,x86_64-apple-darwin,x86_64-pc-windows-msvc
18 changes: 18 additions & 0 deletions .github/workflows/deploy-mkdocs-on-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Deploy MkDocs on latest commit

on:
push:
branches:
- main
- master

jobs:
deploy-mkdocs:
uses: deargen/workflows/.github/workflows/deploy-mkdocs.yml@master
with:
deploy-type: latest
requirements-file: deps/lock/x86_64-unknown-linux-gnu/requirements_docs.txt
gitlab-project: ${{ vars.GITLAB_PROJECT }}
gitlab-branch: gl-pages
secrets:
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
137 changes: 24 additions & 113 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,123 +1,34 @@
name: Deploy a new version
name: Commit CHANGELOG.md, create a Release and deploy MkDocs

on:
workflow_dispatch:
inputs:
version_tag:
description: 'Version tag'
version-tag:
description: Version tag
required: true
default: v0.1.0
dry_run:
dry-run:
description: Dry run
type: boolean
description: 'Dry run'
default: false

jobs:
dry-run:
if: ${{ github.event.inputs.dry_run == 'true' }}
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Push new version tag temporarily for changelog generation
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git tag -a ${{ github.event.inputs.version_tag }} -m ${{ github.event.inputs.version_tag }}
git push --tags

- name: Get CHANGELOG
id: changelog-dry-run
uses: requarks/changelog-action@v1.10.2
with:
includeInvalidCommits: true
excludeTypes: build,docs,style,other
token: ${{ github.token }}
tag: ${{ github.event.inputs.version_tag }}

- name: Display CHANGELOG
if: ${{ github.event.inputs.dry_run == 'true' }}
run: |
echo '${{ steps.changelog-dry-run.outputs.changes }}'
echo '${{ steps.changelog-dry-run.outputs.changes }}' > "$GITHUB_STEP_SUMMARY"

- name: Remove temporary version tag
if: ${{ github.event.inputs.dry_run == 'true' }}
run: |
git tag -d ${{ github.event.inputs.version_tag }}
git push origin --delete ${{ github.event.inputs.version_tag }}

deploy:
if: ${{ github.event.inputs.dry_run == 'false' }}
runs-on: ubuntu-latest
environment: mkdocs

steps:
- uses: actions/checkout@v4
- name: Push new version tag temporarily for changelog generation
run: |
git config user.name github-actions[bot]
git config user.email github-actions[bot]@users.noreply.github.com
git tag -a ${{ github.event.inputs.version_tag }} -m ${{ github.event.inputs.version_tag }}
git push --tags

- name: Update CHANGELOG
id: changelog
uses: requarks/changelog-action@v1.10.2
with:
includeInvalidCommits: true
excludeTypes: build,docs,style,other
token: ${{ github.token }}
tag: ${{ github.event.inputs.version_tag }}
changelogFilePath: docs/CHANGELOG.md

- name: Commit docs/CHANGELOG.md and update tag
run: |
git tag -d ${{ github.event.inputs.version_tag }}
git push origin --delete ${{ github.event.inputs.version_tag }}
git add docs/CHANGELOG.md
git commit -m "docs: update docs/CHANGELOG.md for ${{ github.event.inputs.version_tag }} [skip ci]"
git tag -a ${{ github.event.inputs.version_tag }} -m ${{ github.event.inputs.version_tag }}
git push
git push --tags

- name: Create Release
uses: ncipollo/release-action@v1.14.0
with:
allowUpdates: true
draft: false
makeLatest: true
name: ${{ github.event.inputs.version_tag }}
tag: ${{ github.event.inputs.version_tag }}
body: ${{ steps.changelog.outputs.changes }}

- name: Run mkdocs
run: |
pip3 install uv
uv venv
source .venv/bin/activate
uv pip install -r deps/x86_64-unknown-linux-gnu/requirements_docs.txt

set +e # Do not exit shell on failure
export HTTPS_REMOTE="https://gitlab-ci-token:${{ secrets.GL_TOKEN }}@gitlab.com/${{ vars.GL_PROJECT }}.git"

git remote add gitlab "$HTTPS_REMOTE"
git branch -D gl-pages
git pull gitlab gl-pages:gl-pages

# Delete the latest page because we're going to make it as an alias to the latest version.
mike delete --deploy-prefix public -r "$HTTPS_REMOTE" -b gl-pages latest
out=$(mike deploy --deploy-prefix public -r "$HTTPS_REMOTE" -p -b gl-pages -u ${{ github.event.inputs.version_tag }} latest 2> stderr.txt)
exit_code=$?
err=$(<stderr.txt)

mike set-default --deploy-prefix public -r "$HTTPS_REMOTE" -p -b gl-pages latest

# Display the raw output in the step
echo "${out}"
echo "${err}"

# Display the Markdown output in the job summary
{ echo "\`\`\`python"; echo "${out}"; echo "${err}"; echo "\`\`\`"; } >> "$GITHUB_STEP_SUMMARY"

exit ${exit_code}
commit-changelog-and-release:
uses: deargen/workflows/.github/workflows/commit-changelog-and-release.yml@master
with:
version-tag: ${{ github.event.inputs.version-tag }}
dry-run: ${{ github.event.inputs.dry-run == true }}
changelog-path: docs/CHANGELOG.md
exclude-types: build,docs,style,other

deploy-mkdocs:
needs: commit-changelog-and-release
uses: deargen/workflows/.github/workflows/deploy-mkdocs.yml@master
with:
requirements-file: deps/lock/x86_64-unknown-linux-gnu/requirements_docs.txt
gitlab-project: ${{ vars.GITLAB_PROJECT }}
gitlab-branch: gl-pages
version-tag: ${{ github.event.inputs.version-tag }}
deploy-type: tag
secrets:
GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }}
48 changes: 0 additions & 48 deletions .github/workflows/docs.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/gen-init-py.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Generate __init__.py files

on:
workflow_dispatch:
inputs:
src-dir:
description: src directory
required: true
default: src

jobs:
generate-init-py:
name: Generate __init__.py files
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: deargen/workflows/actions/gen-init-py@master
with:
src-dir: ${{ github.event.inputs.src-dir }}
Loading