-
Notifications
You must be signed in to change notification settings - Fork 0
101 lines (96 loc) · 2.86 KB
/
cd.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
---
## continuous deployment workflow
name: cd
on:
# push:
# branches:
# - main
workflow_dispatch:
permissions:
contents: read
jobs:
lint:
name: Run linting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: false
ref: ${{ github.sha || 'main' }}
- uses: actions/setup-python@v5
with:
python-version-file: .python-version
cache-dependency-path: pyproject.toml
- name: Lint
run: make lint
test-python:
runs-on: ubuntu-latest
needs: lint
strategy:
matrix:
python-version: [3.8, 3.9, 3.10, 3.11, 3.12]
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: false
ref: ${{ github.sha || 'main' }}
- uses: actions/setup-python@v5
with:
python-version-file: ${{ matrix.python-version }}
cache-dependency-path: pyproject.toml
- name: test
run: make test
- name: it-test
run: make it-test
release:
runs-on: ubuntu-latest
needs: [lint, test-python]
permissions:
# write permission is required to create a github release
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
fetch-tags: false
ref: ${{ github.sha || 'main' }}
- uses: actions/setup-python@v5
with:
python-version-file: .python-version
cache-dependency-path: pyproject.toml
- name: Check version change
uses: actions/github-script@v7
id: check_version
with:
script: |
const fs = require('fs');
const version = fs.readFileSync('src/pytest_otel/__init__.py', 'utf8').match(/__version__ = (.*)/)[1].trim();
const { data: latestRelease } = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
})
if (latestRelease.tag_name === version) {
core.setOutput('release', 'false' );
} else {
core.setOutput('release', 'true' );
core.setOutput('version', version );
}
- name: Release
if: ${{ steps.check_version.outputs.release == 'true'}}
id: release
run: make publish
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
REPO_URL: ${{ secrets.REPO_URL }}
- uses: release-drafter/release-drafter@v6
if: ${{ steps.check_version.outputs.release == 'true'}}
with:
version: ${{ steps.release.outputs.version }}
publish: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}