Skip to content

Commit 9dac3ba

Browse files
committed
feat: initial commit
Set up core files for repo, describe purpose of repo, configure pre-commit and set up GitHub workflows.
0 parents  commit 9dac3ba

File tree

12 files changed

+511
-0
lines changed

12 files changed

+511
-0
lines changed

.cspell/custom_misc.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
GCHQ

.cspell/library_terms.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
autoupdate
2+
coreax
3+
jumanjihouse
4+
vars

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Force all files to be indexed with LF line endings except those listed below
2+
* text
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
name: Autoupdate pre-commit config
3+
4+
on:
5+
schedule:
6+
- cron: "0 0 * * 0"
7+
8+
jobs:
9+
pre_commit_autoupdate:
10+
env:
11+
config_path: .pre-commit-config.yaml
12+
update_message_path: /tmp/message.txt
13+
update_branch: chore/pre-commit-autoupdate
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Generate a token
17+
id: generate-token
18+
uses: actions/create-github-app-token@v1
19+
with:
20+
app-id: ${{ vars.WRITE_CONTENTS_PR_APP }}
21+
private-key: ${{ secrets.WRITE_CONTENTS_PR_KEY }}
22+
- uses: actions/checkout@v4
23+
with:
24+
ref: main
25+
- name: Create or checkout update branch
26+
id: create_branch
27+
env:
28+
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
29+
run: |
30+
export pr_number=$( gh pr view ${{ env.update_branch }} --json number --jq '.number' )
31+
export pr_state=$( gh pr view ${{ env.update_branch }} --json state --jq '.state' )
32+
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
33+
echo "pr_state=$pr_state" >> "$GITHUB_OUTPUT"
34+
35+
if git fetch origin ${{ env.update_branch }}; then
36+
# If branch wasn't deleted after merge, do so here
37+
if [ "$pr_state" = "MERGED" ]; then
38+
git push -d origin ${{ env.update_branch }}
39+
git checkout -b ${{ env.update_branch }}
40+
git push origin ${{ env.update_branch }}
41+
fi
42+
git checkout ${{ env.update_branch }}
43+
else
44+
git checkout -b ${{ env.update_branch }}
45+
git push origin ${{ env.update_branch }}
46+
fi
47+
48+
# Pre-commit setup and autoupdate steps
49+
- name: Set up Python
50+
uses: actions/setup-python@v5
51+
with:
52+
python-version: 3.13
53+
cache: pip
54+
- name: Upgrade Pip
55+
run: python -m pip install --upgrade pip
56+
- name: Install pre-commit
57+
run: pip install pre-commit
58+
- name: Store hash of baseline pre-commit config for comparison
59+
id: old_file
60+
run: echo "hash=$( sha256sum $config_path )" >> $GITHUB_OUTPUT
61+
- name: Overwrite config on branch with version from main
62+
run: git checkout main ${{ env.config_path }}
63+
- name: Store hash of main pre-commit config for comparison
64+
id: main_file
65+
run: echo "hash=$( sha256sum $config_path )" >> $GITHUB_OUTPUT
66+
- name: Run pre-commit autoupdate on main pre-commit config
67+
id: autoupdate
68+
run: |
69+
pre-commit autoupdate > ${{ env.update_message_path }}
70+
sed -i "/updating/!d" ${{ env.update_message_path }}
71+
- name: Store hash of new pre-commit config for comparison
72+
id: new_file
73+
run: echo "hash=$( sha256sum $config_path )" >> $GITHUB_OUTPUT
74+
# Commit authoring and pull-request creation/updating
75+
- name: Commit (with signature) pre-commit config
76+
id: commit
77+
if: steps.old_file.outputs.hash != steps.new_file.outputs.hash
78+
env:
79+
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
80+
run: |
81+
export message="chore(deps): autoupdate pre-commit hooks"
82+
export sha=$( git rev-parse ${{ env.update_branch }}:${{ env.config_path }} )
83+
export content=$( base64 -i ${{ env.config_path }} )
84+
gh api --method PUT /repos/:owner/:repo/contents/${{ env.config_path }} \
85+
--field message="$message" \
86+
--field content="$content" \
87+
--field branch=${{ env.update_branch }} \
88+
--field sha="$sha"
89+
- name: Create or update pre-commit-autoupdate pull-request
90+
if: steps.commit.conclusion == 'success' || ( steps.main_file.outputs.hash != steps.new_file.outputs.hash )
91+
env:
92+
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
93+
run : |
94+
export title="chore(deps): autoupdate pre-commit hooks"
95+
export body=$( cat ${{ env.update_message_path }} )
96+
export pr_number=${{ steps.create_branch.outputs.pr_number }}
97+
export pr_state=${{ steps.create_branch.outputs.pr_state }}
98+
99+
# If the PR is closed, can it be reopened, or is the PR already open?
100+
if ( [ "$pr_state" = "CLOSED" ] && gh pr reopen $pr_number ) || [ "$pr_state" = "OPEN" ]; then
101+
gh api --method PATCH /repos/:owner/:repo/pulls/$pr_number \
102+
--field title="$title" \
103+
--field body="$body"
104+
else
105+
# If a PR doesn't already exist, and no previous PR can be reopened, create a new PR.
106+
gh pr create -t "$title" -b "$body" -l dependencies -B main -H ${{ env.update_branch }}
107+
fi
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: Pre-commit Checks
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
branches:
10+
- "**"
11+
12+
jobs:
13+
pre_commit:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: 3.13
21+
cache: pip
22+
- name: Upgrade Pip
23+
run: python -m pip install --upgrade pip
24+
- name: Install pre-commit
25+
run: pip install pre-commit
26+
- name: Run Pre-commit checks
27+
run: SKIP=no-commit-to-branch pre-commit run -a --show-diff-on-failure

.gitignore

Whitespace-only changes.

.pre-commit-config.yaml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
default_install_hook_types:
3+
- pre-commit
4+
- pre-merge-commit
5+
- commit-msg
6+
default_stages:
7+
- pre-commit
8+
- pre-merge-commit
9+
repos:
10+
- repo: https://github.com/pre-commit/pre-commit-hooks
11+
rev: v5.0.0
12+
hooks:
13+
# Reject commits that add large files (coverage.xml, for example)
14+
# Consider adjusting kB limit
15+
- id: check-added-large-files
16+
args:
17+
- --enforce-all
18+
- --maxkb=5000
19+
# Check for files that would conflict in case-insensitive filesystems
20+
- id: check-case-conflict
21+
# Check for files that contain merge conflict strings
22+
- id: check-merge-conflict
23+
# Check syntax of data files
24+
- id: check-json
25+
- id: check-toml
26+
- id: check-yaml
27+
# Files must end in a single newline
28+
- id: end-of-file-fixer
29+
# Remove whitespace at the end of lines
30+
- id: trailing-whitespace
31+
# Prevent commit to main/master
32+
- id: no-commit-to-branch
33+
# Sort spell check custom dictionary
34+
- id: file-contents-sorter
35+
files: ^.cspell/.+.txt$
36+
args:
37+
- --ignore-case
38+
- --unique
39+
- repo: local
40+
hooks:
41+
# Check files are valid UTF-8
42+
- id: require-utf8
43+
name: Check file encoding
44+
description: Ensure file is valid UTF-8
45+
entry: python pre_commit_hooks/require_utf8.py
46+
language: python
47+
# Keep requirements-docs.txt in sync with uv.lock
48+
- repo: https://github.com/Lucas-C/pre-commit-hooks
49+
rev: v1.5.5
50+
hooks:
51+
# No tabs, only spaces
52+
- id: forbid-tabs
53+
- repo: https://github.com/streetsidesoftware/cspell-cli
54+
rev: v8.16.0
55+
hooks:
56+
# Run a spellcheck (words pulled from cspell.config.yaml)
57+
- id: cspell
58+
stages:
59+
- pre-commit
60+
- pre-merge-commit
61+
- commit-msg
62+
exclude_types:
63+
- gitignore
64+
exclude: .cspell/.*

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Contributor guidelines
2+
3+
We strongly encourage contributions to Coreax. Please follow the guidelines
4+
[there](https://github.com/gchq/coreax/blob/main/CONTRIBUTING.md). Issues should be
5+
reported to the main Coreax [issues board](https://github.com/gchq/coreax/issues).
6+
7+
## Pre-commit
8+
9+
This repo runs pre-commit checks. Please run `pre-commit install` before making any
10+
commits.

0 commit comments

Comments
 (0)