-
Notifications
You must be signed in to change notification settings - Fork 6
158 lines (141 loc) · 4.87 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
name: Lint & release project
on:
push:
paths:
- "pyproject.toml"
- "poetry.lock"
- "tgpy/**"
- ".github/workflows/main.yml"
- ".github/workflows/docker.yml"
pull_request:
paths:
- "pyproject.toml"
- "poetry.lock"
- "tgpy/**"
- ".github/workflows/main.yml"
- ".github/workflows/docker.yml"
workflow_dispatch: {}
jobs:
lint:
runs-on: ubuntu-latest
name: Lint
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a
- name: Load dependency cache
id: load-cache
uses: actions/cache@v4
with:
path: .venv
key: app-${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('poetry.lock') }}
- name: Install dependencies
run: |
poetry config virtualenvs.in-project true
poetry install
if: steps.load-cache.outputs.cache-hit != 'true'
- name: Check code style
if: github.event_name != 'push'
run: |
poetry run black --check --diff .
poetry run isort --check --diff .
- name: Reformat code
if: github.event_name == 'push'
run: |
poetry run black .
poetry run isort .
- name: Commit chanes
if: github.event_name == 'push'
shell: bash
run: |
if [ ! -n "$(git status --porcelain)" ]; then
exit
fi
git add -A
git config user.name "github-actions"
git config user.email "[email protected]"
git commit -m "style: reformat [skip ci]"
git push
release:
name: Release
needs: lint
concurrency: release
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: DeterminateSystems/nix-installer-action@main
- uses: DeterminateSystems/magic-nix-cache-action@main
- uses: nicknovitski/nix-develop@9be7cfb4b10451d3390a75dc18ad0465bed4932a
- name: Load dependency cache
id: load-cache
uses: actions/cache@v4
with:
path: .venv
key: app-${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('poetry.lock') }}
- name: Install dependencies
run: |
poetry config virtualenvs.in-project true
poetry install --with release
if: steps.load-cache.outputs.cache-hit != 'true'
- name: Create a release
id: release-version
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
source .venv/bin/activate
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
python -m semantic_release version
echo "version-tag=$(python -m semantic_release version --print-tag)" >> $GITHUB_OUTPUT
- name: Publish package distributions to GitHub Releases
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_TAG: ${{ steps.release-version.outputs.version-tag }}
run: |
source .venv/bin/activate
python -m semantic_release -v publish --tag $GH_TAG
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Save release commit hash
id: release-commit-hash
run: echo "release-commit-hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
outputs:
release-commit-hash: ${{ steps.release-commit-hash.outputs.release-commit-hash }}
publish-to-pypi:
name: Publish Python distribution to PyPI
needs: release
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/tgpy
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
build-dev-docker:
needs: lint
name: Build dev docker image
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref != 'refs/heads/master'
uses: ./.github/workflows/docker.yml
secrets: inherit
build-release-docker:
name: Build release docker image
needs: release
if: (github.event_name == 'push' || github.event_name == 'workflow_dispatch') && github.ref == 'refs/heads/master'
uses: ./.github/workflows/docker.yml
with:
commit-hash: ${{ needs.release.outputs.release-commit-hash }}
secrets: inherit