Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelzw committed Jan 28, 2024
0 parents commit dcef678
Show file tree
Hide file tree
Showing 25 changed files with 3,783 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# GitHub syntax highlighting
pixi.lock linguist-language=YAML

1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @quantco/ci
26 changes: 26 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: 2
registries:
github:
type: git
url: https://github.com
username: x-access-token
password: ${{ secrets.DEPENDABOT_CONTENT_PAT }}
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
registries:
- github
groups:
dependencies:
patterns:
- "*"
- package-ecosystem: github-actions
directory: /template/.github/workflows
schedule:
interval: daily
groups:
dependencies:
patterns:
- "*"
92 changes: 92 additions & 0 deletions .github/workflows/bump-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Bump versions
on:
workflow_dispatch:
schedule:
- cron: 0 6 * * *

jobs:
generate-tools:
name: Get all tools
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.setmatrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- name: Get all tools
id: setmatrix
shell: python
run: |
import os
import json
from pathlib import Path
tools = {}
# incompatible with subdirectory actions
skip_actions = ["Quantco/ui-actions/version-metadata"]
for file in Path("template/.github/workflows").glob("*"):
content = file.read_text()
# go over every `uses: ` line
for line in content.splitlines():
if "uses: " in line:
# extract the action name
action, version = line.split("uses: ", 1)[1].split("@", 1)
if action in skip_actions:
# not possible because it's a private repository
continue
tools[action] = ("major" if version.startswith("v") else "sha")
matrix = []
for tool, versioning in tools.items():
matrix.append({"tool": tool, "versioning": versioning})
with open(os.environ["GITHUB_OUTPUT"], "w") as f:
f.write(f"matrix={json.dumps(matrix)}")
bump:
needs: [generate-tools]
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.generate-tools.outputs.matrix) }}
name: Bump ${{ matrix.tool }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
# needed s.t. the workflows have permissions to run when the PR is created
ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
ref: ${{ github.head_ref }}
- name: Bump versions
id: bump
run: |
set -exuo pipefail
new_version="$(gh repo view --json latestRelease ${{ matrix.tool }} | jq -r '.latestRelease.tagName')"
if [[ ${{ matrix.versioning }} = "sha" ]]; then
echo "new-version=$new_version" >> "$GITHUB_OUTPUT"
commit_sha="$(gh api "repos/${{ matrix.tool }}/commits/$new_version" | jq -r '.sha')"
for file in ./template/.github/workflows/*; do
sed -i -e "s#${{ matrix.tool }}@.*#${{ matrix.tool }}@${commit_sha}#g" "$file"
done
elif [[ ${{ matrix.versioning }} = "major" ]]; then
new_version_major="$(echo "$new_version" | cut -d. -f1)"
echo "new-version=$new_version_major" >> "$GITHUB_OUTPUT"
for file in ./template/.github/workflows/*; do
sed -i -e "s#${{ matrix.tool }}@.*#${{ matrix.tool }}@${new_version_major}#g" "$file"
done
else
echo "Unknown versioning scheme: ${{ matrix.versioning }}"
exit 1
fi
git diff
env:
GH_TOKEN: ${{ github.token }}
- name: Create Pull Request
uses: peter-evans/create-pull-request@153407881ec5c347639a548ade7d8ad1d6740e38
with:
title: Bump ${{ matrix.tool }} to ${{ steps.bump.outputs.new-version }}
delete-branch: true
commit-message: Bump ${{ matrix.tool }} version to ${{ steps.bump.outputs.new-version }}
branch: bump-${{ matrix.tool }}-${{ steps.bump.outputs.new-version }}
labels: dependencies
26 changes: 26 additions & 0 deletions .github/workflows/ci-copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI Copier
on: [push]

# Automatically stop old builds on the same branch/PR
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
linux-unittests:
name: Check project generation
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # copier doesn't like shallow clones
- name: Set up pixi
uses: prefix-dev/setup-pixi@ca3b9ac762955fad216e3d8e0bbf22087071c89c
- name: Run unittests
uses: quantco/pytest-action@v2
with:
report-title: Check project generation
click-to-expand: false
custom-pytest: pixi run pytest
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# pixi environments
.pixi

__pycache__
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# copier-template-pre-commit-mirrors

This is a template for our pre-commit mirrors.

To create a new mirror, you can run the following command

```bash
pixi run generate /path/to/mirror
```
31 changes: 31 additions & 0 deletions copier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# configuration
_subdirectory: template
_min_copier_version: '9.1.1'

# questions
tool:
type: str
help: What is the name of the tool?
validator: >-
{% if entry == '' %}
Please provide a valid tool name
{% endif %}
url:
type: str
help: What is the URL of the tool?
validator: >-
{% if not url.startswith('https://') %}
Please provide a URL
{% endif %}
entry:
type: str
help: What is the pre-commit entry (for example `ruff --fix --exit-non-zero-on-fix`)?
validator: >-
{% if entry == '' %}
Please provide an entry
{% endif %}
_tasks:
- sed -i "s/TOOL_VERSION/$(micromamba search -c conda-forge {{ tool }} --json | jq -r '.result.pkgs[0].version')/g" environment.yml
- git init
- git branch -M main
Loading

0 comments on commit dcef678

Please sign in to comment.