Skip to content

Commit

Permalink
feat!: change template pipeline to github
Browse files Browse the repository at this point in the history
  • Loading branch information
pppmlt committed Aug 29, 2022
1 parent 46b315e commit f629096
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 55 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/format_and_lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# This is a basic workflow to help you get started with Actions
name: format_and_lint

# Controls when the workflow will run
on:
# Triggers the workflow on pull request to the main branch
pull_request:
branches:
- main

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
format_and_lint:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: setup environment
uses: mamba-org/provision-with-micromamba@main
with:
environment-file: environment.yaml
# Runs a set of commands using the runners shell
- name: run pre-commit & check commit msgs
shell: bash -l {0}
run: |
micromamba activate data-science-project-template
pre-commit install
pre-commit run --hook-stage manual --all-files
git fetch
export branch_name=${{ github.ref_name }}
if [[ ${{ github.event_name }} == "pull_request" ]]; then export branch_name=${{ github.head_ref}}; fi
./check_commit_msgs.sh -c "remotes/origin/${branch_name}" -m "remotes/origin/${{ github.event.repository.default_branch }}"
22 changes: 22 additions & 0 deletions .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: semantic-release

# trigger a release of a new version if commits are added to the default branch (e.g., main)
on:
push:
branches:
- 'main'

env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
tag_release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: '16'
- run: npm install semantic-release conventional-changelog-conventionalcommits
- run: npx semantic-release
11 changes: 0 additions & 11 deletions .gitlab-ci-release.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions .gitlab-ci-stages.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions .gitlab-ci-test.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions .gitlab-ci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .releaserc.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
}
}
],
"@semantic-release/gitlab"
"@semantic-release/github"
],
"branches": "main"
}
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
# HSG Data Science Template
# HSG Data Science Project Template

The HSG Data Science Project Template is a `cookiecutter` template to configure data science project repositories.
It features/configures:

- a default `gitignore` file
- a default `data/raw` folder tracked by `git-lfs`
- line endings set to LF on check-in for text files (based on `git` heuristic for text file detection)
- `pre-commit` checks including:
- code formatting of `python` and `.ipynb` files with `black`
- code linting of `python` and `.ipynb` files with `pylint`
- code formatting/checking for various configuration file types (e.g., `.yaml`)
- check of commit messages according to [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) specifications
- configuration to run code formatting & linting with `gitlab` ci/cd pipelines

## Prerequisites

Expand All @@ -14,7 +27,7 @@ The template depends on the following software:
To setup a new project with the HSG data science template create the project repository in gitlab, run

```
cookiecutter https://ac1-git1.umlaut.com/hsg/hsg/data-science/data-science-templates/data-science-project-template.git
cookiecutter https://github.com/HotSprings-GmbH/data-science-project-template
```

and fill out the needed information.
Expand All @@ -33,14 +46,9 @@ and start developing.

## Setup CI/CD pipelines in gitlab

The project is set up to run:

- `pre-commit` checks on every new commit pushed to gitlab
- `semantic-release` on every MR to main
The projects created with this template are set up to run the formatting and linting checks configured
in `pylint` for every new commit pushed to `gitlab`. The CI/CD pipelines must be enabled within the gitlab repository settings (`Settings -> General -> Visibility, project features, permissions`).

To enable the CI/CD setup in gitlab please use the following steps:
## License

- enable `CI/CD` pipelines in `Settings -> General -> Visibility, project features, permissions`.
- create a project access token named `GITLAB_TOKEN` in `Settings -> Access Tokens` with `Maintainer` role and `api` + `write_repository` scopes.
- copy the token value appearing at the top of the page after the token creation
- create a `masked` and `protected` variable called `GITLAB_TOKEN` in `CI/CD -> Variables` using the previously created token value
Licensed under the Apache License, Version 2.0 (the "License").

0 comments on commit f629096

Please sign in to comment.