-
Notifications
You must be signed in to change notification settings - Fork 0
173 lines (161 loc) · 4.98 KB
/
trunk.yml
File metadata and controls
173 lines (161 loc) · 4.98 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
name: trunk
on:
push:
workflow_dispatch:
jobs:
test:
name: Run tests
runs-on: ubuntu-latest
outputs:
version-changed: ${{ steps.changes.outputs.version }}
steps:
- uses: actions/checkout@v6
- uses: psf/black@stable
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: 'pip'
- name: Install hatch
run: >-
python3 -m
pip install
hatch
- name: Run tests
run: hatch test || exit 0
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
version:
- 'src/nmapp/__about__.py'
build:
name: Build Python Wheel 📦
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && needs.test.outputs.version-changed == 'true'
needs:
- test
outputs:
our-version-major: ${{ steps.our-version-major.outputs.version }}
our-version-minor: ${{ steps.our-version-minor.outputs.version }}
our-version-full: ${{ steps.our-version-full.outputs.version }}
steps:
- uses: actions/checkout@v6
- id: our-version-major
run: |
echo version=$(grep -oP '(?<=__version__ = ")[^"]*' src/nmapp/__about__.py | cut -d '.' -f 1) >> $GITHUB_OUTPUT
- id: our-version-minor
run: |
echo version=$(grep -oP '(?<=__version__ = ")[^"]*' src/nmapp/__about__.py | cut -d '.' -f 2) >> $GITHUB_OUTPUT
- id: our-version-full
run: |
echo version=$(grep -oP '(?<=__version__ = ")[^"]*' src/nmapp/__about__.py) >> $GITHUB_OUTPUT
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: 'pip'
- name: Install hatch
run: >-
python3 -m
pip install
hatch
- name: Build a binary wheel and a source tarball
run: hatch build
- name: Store the distribution packages
uses: actions/upload-artifact@v6
with:
name: python-package-distributions
path: dist/
build-and-push-image:
name: Build and push container image to GHCR
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && needs.test.outputs.version-changed == 'true'
needs:
- test
- build
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Download all the dists
uses: actions/download-artifact@v7
with:
name: python-package-distributions
path: dist/
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
file: Dockerfile
context: .
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: |
ghcr.io/hacktegic/nmapp:${{ needs.build.outputs.our-version-full }}
ghcr.io/hacktegic/nmapp:${{ needs.build.outputs.our-version-major }}
ghcr.io/hacktegic/nmapp:latest
# publish-to-pypi:
# name: >-
# Publish 📦 to PyPI
# if: github.ref == 'refs/heads/main' && needs.test.outputs.version-changed == 'true'
# needs:
# - test
# - build
# runs-on: ubuntu-latest
# environment:
# name: pypi
# url: https://pypi.org/p/nmapp
# permissions:
# id-token: write # IMPORTANT: mandatory for trusted publishing
# steps:
# - name: Download all the dists
# uses: actions/download-artifact@v7
# with:
# name: python-package-distributions
# path: dist/
# - name: Publish distribution 📦 to PyPI
# uses: pypa/gh-action-pypi-publish@release/v1
# with:
# packages-dir: dist/
# verbose: true
release:
name: >-
Create GitHub Release
if: github.ref == 'refs/heads/main' && needs.test.outputs.version-changed == 'true'
permissions:
contents: write
runs-on: ubuntu-latest
needs:
- build
- build-and-push-image
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: '0'
- name: Bump version and push tag
uses: anothrNick/github-tag-action@1.75.0
env:
CUSTOM_TAG: ${{ needs.build.outputs.our-version-full }}
GITHUB_TOKEN: ${{ github.token }}
- name: Release
uses: softprops/action-gh-release@v2
with:
draft: true
prerelease: true
name: ${{ needs.build.outputs.our-version-full }}
tag_name: ${{ needs.build.outputs.our-version-full }}
generate_release_notes: true
token: ${{ github.token }}