Skip to content

Commit

Permalink
Merge pull request #4 from spraakbanken/graph-init
Browse files Browse the repository at this point in the history
graph init
  • Loading branch information
kod-kristoff authored May 6, 2024
2 parents 4eae37c + 3390f01 commit f492874
Show file tree
Hide file tree
Showing 41 changed files with 3,059 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/DOCS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Github config and workflows

In this folder there is configuration for codecoverage, dependabot and ci workflows.

This folder can be merged using a `--allow-unrelated-histories` merge strategy from <https://github.com/spraakbanken/python-pdm-ci-conf> which provides a reasonably sensible base for writing your own ci on. By using this strategy the history of the CI repo is included in your repo, and future updates to the CI can be merged later.

The workflows in this folder requires a root Makefile with a couple of targets defined.
As base can the Makefile in <https://github.com/spraakbanken/python-pdm-make-conf> be used.

## Publish

The `publish`-step in [test.yml](./workflows/test.yml) is configured to use the GitHub environment `release`, create that or change to your preferred environment.
To publish to PyPI you must also configure your Pypi-project settings to use Trusted Publisher Management, by setting repo, workflow and environment on PyPI.

To perform this merge run:

```shell
git remote add ci [email protected]:spraakbanken/python-pdm-ci-conf.git
git fetch ci
git merge --allow-unrelated-histories ci/main
```

or add the remote as `git remote add ci https://github.com/spraakbanken/python-pdm-ci-conf.git`

To later merge updates to this repo, just run:

```shell
git fetch ci
get merge ci/main
```

This setup is inspired by <https://github.com/jonhoo/rust-ci-conf>.
21 changes: 21 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ref: https://docs.codecov.com/docs/codecovyml-reference
coverage:
# Hold ourselves to a high bar
range: 85..100
round: down
precision: 1
status:
# ref: https://docs.codecov.com/docs/commit-status
project:
default:
# Avoid false negatives
threshold: 1%

# Test files aren't important for coverage
ignore:
- "tests"

# Make comments less noisy
comment:
layout: "files"
require_changes: true
25 changes: 25 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "daily"
ignore:
- dependency-name: "*"
# patch and minor updates don't matter for libraries as consumers of this library build
# with their own lockfile, rather than the version specified in this library's lockfile
# remove this ignore rule if your package has binaries to ensure that the binaries are
# built with the exact set of dependencies and those are up to date.
update-types:
- "version-update:semver-patch"
- "version-update:semver-minor"
111 changes: 111 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: check

on:
push:
branches:
- main
pull_request:
merge_group:

permissions:
contents: read

env:
MINIMUM_PYTHON_VERSION: "3.8"

# If new code is pushed to a PR branch, then cancel in progress workflows for that PR. Ensures that
# we don't waste CI time, and returns results quicker https://github.com/jonhoo/rust-ci-conf/pull/5
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
fmt:
runs-on: ubuntu-latest
name: ubuntu / 3.8 / fmt
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Set up the python ${{ env.MINIMUM_PYTHON_VERSION }}
uses: pdm-project/setup-pdm@v4
id: setup-python
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}

- name: Load cached venv
id: cached-venv
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/pdm.lock') }}-${{ hashFiles('.github/workflows/check.yml') }}

- name: Install dependencies
if: steps.cached-venv.outputs.cache-hit != 'true'
run: make install-dev

- name: check formatting
run: make check-fmt
lint:
runs-on: ubuntu-latest
name: ubuntu / 3.8 / lint
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up the python ${{ env.MINIMUM_PYTHON_VERSION }}
uses: pdm-project/setup-pdm@v4
id: setup-python
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
- name: Load cached venv
id: cached-venv
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/pdm.lock') }}-${{ hashFiles('.github/workflows/check.yml') }}
- name: Install dependencies
if: steps.cached-venv.outputs.cache-hit != 'true'
run: make install-dev
- name: lint code
run: make lint
type-check:
runs-on: ubuntu-latest
name: ubuntu / 3.8 / type-check
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up the python ${{ env.MINIMUM_PYTHON_VERSION }}
uses: pdm-project/setup-pdm@v4
id: setup-python
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
- name: Load cached venv
id: cached-venv
uses: actions/cache@v4
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('**/pdm.lock') }}-${{ hashFiles('.github/workflows/check.yml') }}
- name: Install dependencies
if: steps.cached-venv.outputs.cache-hit != 'true'
run: make install-dev
- name: type-check code
run: make type-check

# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
check-check:
if: always()
needs:
- fmt
- lint
- type-check
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
allowed-failures: upload-coverage
138 changes: 138 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: release

on:
push:
branches:
- main
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
pull_request:
merge_group:

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
permissions:
contents: read

env:
MINIMUM_PYTHON_VERSION: "3.8"

jobs:
build:
# This action builds distribution files for upload to PyPI

name: ubuntu / 3.8 / build
runs-on: ubuntu-latest
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v4
with:
submodules: true

#----------------------------------------------
# ----- setup python -----
#----------------------------------------------
- name: Set up the environment
uses: pdm-project/setup-pdm@v4
id: setup-python
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}

#----------------------------------------------
# ----- build distribution -----
#----------------------------------------------
- name: Build distribution
run: make build

#----------------------------------------------
# ----- upload artifacts -----
#----------------------------------------------
- uses: actions/upload-artifact@v4
with:
name: pypi_files
path: dist

test-build:
# This action runs the test suite on the built artifact in the `build` action.
# The default is to run this in ubuntu, macos and windows

name: ${{ matrix.os }} / 3.8 / test built artifact
needs: [build]

strategy:
fail-fast: false
matrix:
os:
- ubuntu
- macos
- windows

runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: set up python
uses: actions/setup-python@v5
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}

- name: get dist artifacts
uses: actions/download-artifact@v4
with:
name: pypi_files
path: dist

- run: rm -r src/parallel_corpus
- run: pip install typing-extensions
- run: pip install -r tests/requirements-testing.lock
- run: pip install parallel-corpus --no-index --no-deps --find-links dist --force-reinstall
- run: pytest

# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
release-check:
if: always()
needs:
- build
- test-build
runs-on: ubuntu-latest
permissions: {}
steps:
- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
with:
jobs: ${{ toJSON(needs) }}
# allowed-failures: coverage

publish:
# This action publishes the built and tested artifact to PyPI, but only on a tag

needs:
- test-build
if: success() && startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python ${{ env.MINIMUM_PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
- name: get dist artifacts
uses: actions/download-artifact@v4
with:
name: pypi_files
path: dist

- name: Publish package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
Loading

0 comments on commit f492874

Please sign in to comment.