Skip to content

[pre-commit.ci] pre-commit autoupdate #84

[pre-commit.ci] pre-commit autoupdate

[pre-commit.ci] pre-commit autoupdate #84

Workflow file for this run

name: PR Validation
on:
pull_request:
jobs:
validate-labels:
runs-on: ubuntu-latest
steps:
- name: Check labels
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const {
data: pullRequest
} = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const labels = pullRequest.labels.map(label => label.name);
const invalidLabels = ['feature request', 'invalid', 'question'];
const hasInvalidLabel = labels.some(label => invalidLabels.includes(label));
if (labels.length === 0) {
core.setFailed('Pull request must have at least one label!');
}
if (hasInvalidLabel) {
core.setFailed('Pull request must have an invalid label: ' + invalidLabels.join(', '));
}
- name: Check assignees
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const {
data: pullRequest
} = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
if (pullRequest.assignees.length === 0) {
core.setFailed('Pull request must have an assignee');
}
- name: Check draft status
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# language=JavaScript
script: |
const {
data: pullRequest
} = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
if (pullRequest.draft) {
core.setFailed('Pull request must not be a draft');
}
validate-code:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'poetry'
- name: Install dependencies
run: poetry install
- name: Run Ruff
run: poetry run ruff check --output-format=github .
- name: Run pre-commit hooks
run: poetry run pre-commit run --all-files --show-diff-on-failure
- name: Get version from pyproject.toml
id: get_version
run: |
echo "version=$(poetry version -s)" >> $GITHUB_OUTPUT
validate-branch:
runs-on: ubuntu-latest
needs:
- validate-code
if: startsWith(github.head_ref, 'release/')
steps:
- name: Check branch name with version
run: |
# Extract the branch name from the GitHub context
branch_name=${{ github.head_ref }}
# Check if the branch name starts with "release/" and does not match the version
if [[ $branch_name == release/* && $branch_name != "release/${{ needs.validate-code.outputs.version }}" ]]; then
echo "Branch name does not match the version in pyproject.toml"
exit 1
fi
validate-docker-build:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
packages: read
strategy:
matrix:
platform: [linux/amd64, linux/arm64, linux/arm/v7]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
labels: |
org.opencontainers.image.revision=${{ github.sha }}
tags: |
type=sha,prefix=,suffix=,format=short
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.platform }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.platform }}-
- name: Build Docker image for ${{ matrix.platform }}
uses: docker/build-push-action@v5
id: build-and-push
with:
context: .
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
platforms: ${{ matrix.platform }}