Skip to content
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
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ updates:
# Enable Security updates for Python package manager
- package-ecosystem: pip

# Set to 0 to disable version updates
# When set to 0, version updates are disabled.
open-pull-requests-limit: 10

# Look for a `pyproject.toml`/`requirements.txt/`pipfile.lock` in the `root` directory
Expand Down
17 changes: 6 additions & 11 deletions .github/linters/.markdown-link-check.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
{
"ignorePatterns": [
{
"pattern": "project_urlname",
"reason": "This is a template var that is replaced with the actual project link when the project is created."
},
{
"pattern": "ONSdigital/ons-template",
"reason": "Private repository"
},
{
"pattern": "ONSdigital/ons-python-template",
"reason": "Private repository"
"pattern": "ons-python-template/generate",
"reason": "Generate links require authentication"
}
]
],
"retryOn429": true,
"retryCount": 3,
"fallbackRetryDelay": "30s"
}
11 changes: 0 additions & 11 deletions .github/linters/.project-markdown-link-check.json

This file was deleted.

21 changes: 0 additions & 21 deletions .github/release.yml

This file was deleted.

42 changes: 0 additions & 42 deletions .github/rename_project.sh

This file was deleted.

2 changes: 0 additions & 2 deletions .github/template.yml

This file was deleted.

7 changes: 6 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,19 @@ jobs:
version: 1.7.1
virtualenvs-create: true
virtualenvs-in-project: false
- uses: actions/setup-python@v5

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: .python-version
cache: poetry

- name: Install dependencies
run: |
make install-dev

- name: Lint Python
run: make lint

- name: Test
run: make test
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ on: # yamllint disable-line rule:truthy
- LICENSE
schedule:
# Run on a daily interval at 12pm UTC
- cron: 0 12 * * *
- cron: "0 12 * * *"

concurrency:
group: "${{ github.head_ref || github.ref }}-${{ github.workflow }}"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mega-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:

# You can override MegaLinter flavor used to have faster performances
# More info at https://megalinter.io/latest/flavors/
uses: oxsecurity/megalinter/flavors/python@v7
uses: oxsecurity/megalinter@v7

id: ml

Expand Down
80 changes: 41 additions & 39 deletions .github/workflows/rename-project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ jobs:
uses: actions/github-script@v7
with:
script: |
const repoName = context.repo.repo.replace(/-/g, '_').toLowerCase();
const repoUrlName = context.repo.repo;
const repoName = context.repo.repo;
const repoOwner = context.repo.owner;
core.exportVariable('REPOSITORY_NAME', repoName);
core.exportVariable('REPOSITORY_URLNAME', repoUrlName);
core.exportVariable('REPOSITORY_OWNER', repoOwner);

const repo = await github.rest.repos.get({
Expand All @@ -56,65 +54,69 @@ jobs:
});
const description = repo.data.description;
const visibility = repo.data.visibility;
const isPublic = visibility === 'public';

core.exportVariable('REPOSITORY_DESCRIPTION', description);
core.exportVariable('is_public', isPublic);
core.exportVariable('REPOSITORY_VISIBILITY', visibility);

- name: Rename Repository Check
if: env.is_template == 'false'
run: |
echo "needs_renaming=$(ls .github/template.yml &> /dev/null && echo true || echo false)" >> "$GITHUB_ENV"
echo "needs_renaming=$(ls .github/workflows/rename-project.yml &> /dev/null && echo true || echo false)" >> "$GITHUB_ENV"

- name: Rename project-README.md to README.md
- name: Install Poetry
if: env.is_template == 'false' && env.needs_renaming == 'true'
run: |
mv project-README.md README.md
uses: snok/install-poetry@v1
with:
version: 1.7.1
virtualenvs-create: true
virtualenvs-in-project: false

- name: Set up Python
if: env.is_template == 'false' && env.needs_renaming == 'true'
uses: actions/setup-python@v5
with:
python-version-file: .python-version
cache: poetry

- name: Add markdown-link-check Config File
- name: Install dependencies
if: env.is_template == 'false' && env.needs_renaming == 'true'
run: |
file=".github/linters/.markdown-link-check.json"
mv -f .github/linters/.project-markdown-link-check.json "$file"

if [ "$is_public" = false ]; then
new_pattern='{
"pattern": "author_name/project_urlname",
"reason": "Private repository"
}'
existing_patterns=$(jq '.ignorePatterns' "$file")
if [ "$existing_patterns" = "null" ]; then
jq '.ignorePatterns = [] | .ignorePatterns += [ '"$new_pattern"' ]' "$file" > tmpfile && mv tmpfile "$file"
else
jq '.ignorePatterns += [ '"$new_pattern"' ]' "$file" > tmpfile && mv tmpfile "$file"
fi
fi
make install

- name: Rename the Project
if: env.is_template == 'false' && env.needs_renaming == 'true'
run: |
echo "Renaming the project with -a(author) ${{ env.REPOSITORY_OWNER }} -n(name) ${{ env.REPOSITORY_NAME }} \
-u(urlname) ${{ env.REPOSITORY_URLNAME }} \
-d(description) ${{ env.REPOSITORY_DESCRIPTION || env.REPOSITORY_URLNAME }}"
# Create a temporary directory
temp_dir=$(mktemp -d)

.github/rename_project.sh -a ${{ env.REPOSITORY_OWNER }} -n ${{ env.REPOSITORY_NAME }} \
-u ${{ env.REPOSITORY_URLNAME }} -d "${{ env.REPOSITORY_DESCRIPTION || env.REPOSITORY_URLNAME }}"
# Move .git directory to the temporary directory
mv .git "$temp_dir/"

- name: Remove CodeQL Workflow
if: env.is_template == 'false' && env.needs_renaming == 'true' && env.is_public == 'false'
run: |
rm ".github/workflows/codeql.yml"
# Remove the CodeQL badge from the README
sed -i '/\[!\[Build Status\].*codeql\.yml.*\]/d' README.md
# Run copier
poetry run copier copy "$(pwd)" "$temp_dir" --trust --force --quiet \
--data "repository_name=${{ env.REPOSITORY_NAME }}" \
--data "repository_description=${{ env.REPOSITORY_DESCRIPTION || env.REPOSITORY_NAME }}" \
--data "repository_owner=${{ env.REPOSITORY_OWNER }}" \
--data "repository_visibility=${{ env.REPOSITORY_VISIBILITY }}" \
--data "is_running_in_github_actions=true"

# Remove existing files and directories from the current directory including hidden files
shopt -s dotglob
rm -rf ./*

# Move contents from temporary directory to the current directory
mv -f "$temp_dir"/* .

# Clean up temporary directory
rm -rf "$temp_dir"

- name: Cleanup
if: env.is_template == 'false' && env.needs_renaming == 'true'
run: |
rm .github/rename_project.sh
rm .github/workflows/rename-project.yml

- uses: stefanzweifel/git-auto-commit-action@v5
if: env.is_template == 'false'
if: env.is_template == 'false' && env.needs_renaming == 'true'
with:
commit_message: ✅ Ready to clone and use
commit_message: ✅ Ready to clone
push_options: --force
4 changes: 2 additions & 2 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ community include:
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
- Accepting responsibility and apologszing to those affected by our mistakes,
and learning from the experience
- Focusing on what is best not just for us as individuals, but for the overall
community

Examples of unacceptable behavior include:

- The use of sexualized language or imagery, and sexual attention or advances of
- The use of sexualised language or imagery, and sexual attention or advances of
any kind
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright (c) 2024, ONS Digital
Copyright (c) 2024, Crown Copyright (Office for National Statistics)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
Expand Down
27 changes: 6 additions & 21 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,21 @@ all: ## Show the available make targets.
@echo "Targets:"
@fgrep "##" Makefile | fgrep -v fgrep

.PHONY: format
format: ## Format the code.
poetry run black .
poetry run ruff check . --fix

.PHONY: lint
lint: ## Run all linters (black/ruff/pylint/mypy).
poetry run black --check .
poetry run ruff check .
make mypy
lint: ## Run Python linter
echo "Not implemented yet"

.PHONY: test
test: ## Run the tests and check coverage.
poetry run pytest -n auto --cov=project_name --cov-report term-missing --cov-fail-under=100

.PHONY: mypy
mypy: ## Run mypy.
poetry run mypy project_name
test: ## Run the tests
echo "Not implemented yet"

.PHONY: install
install: ## Install the dependencies excluding dev.
poetry install --only main
poetry install --only main --no-root

.PHONY: install-dev
install-dev: ## Install the dependencies including dev.
poetry install
poetry install --no-root

.PHONY: megalint
megalint: ## Run the mega-linter.
Expand All @@ -43,8 +32,4 @@ megalint: ## Run the mega-linter.

.PHONY: clean
clean: ## Clean the temporary files.
rm -rf .pytest_cache
rm -rf .mypy_cache
rm -rf .coverage
rm -rf .ruff_cache
rm -rf megalinter-reports
Loading