Skip to content

Commit 9f0745c

Browse files
authored
Add PyPI release (#118)
* add pypi publishing and pre-release testing Signed-off-by: Alex Goodman <[email protected]> * update installation and release docs with pypi info Signed-off-by: Alex Goodman <[email protected]> * clean dist before publish Signed-off-by: Alex Goodman <[email protected]> * require poetry dynamic version plugin on build and publish make targets Signed-off-by: Alex Goodman <[email protected]> * split up publishing events from valiadtion Signed-off-by: Alex Goodman <[email protected]> --------- Signed-off-by: Alex Goodman <[email protected]>
1 parent a2c5701 commit 9f0745c

File tree

7 files changed

+122
-27
lines changed

7 files changed

+122
-27
lines changed

.github/actions/bootstrap/action.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,10 @@ runs:
7575
python-version: ${{ inputs.python-version }}
7676

7777
- name: Install poetry
78-
uses: abatilo/[email protected]
79-
with:
80-
poetry-version: ${{ inputs.poetry-version }}
78+
shell: bash
79+
run: |
80+
pipx install poetry==${{ inputs.poetry-version }}
81+
poetry self add "poetry-dynamic-versioning[plugin]"
8182
8283
- name: Cache Poetry virtualenv
8384
uses: actions/cache@v3

.github/workflows/release.yaml

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
echo "Nightly Quality Gate Status: ${{ steps.nightly-quality-gate.conclusion }}"
5454
false
5555
56-
release:
56+
tag:
5757
needs:
5858
- quality-gate
5959
runs-on: ubuntu-20.04
@@ -69,6 +69,48 @@ jobs:
6969
# in order to properly resolve the version from git
7070
fetch-depth: 0
7171

72+
- name: Tag release
73+
run: |
74+
git tag ${{ github.event.inputs.version }}
75+
git push origin --tags
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
79+
release-pypi:
80+
needs:
81+
- tag
82+
runs-on: ubuntu-20.04
83+
environment: release
84+
permissions:
85+
contents: read
86+
steps:
87+
- uses: actions/checkout@v3
88+
with:
89+
# in order to properly resolve the version from git
90+
fetch-depth: 0
91+
92+
- name: Bootstrap environment
93+
uses: ./.github/actions/bootstrap
94+
95+
- name: Publish to PyPI
96+
run: make ci-publish-pypi
97+
env:
98+
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.VUNNEL_PYPI_TOKEN }}
99+
100+
release-docker:
101+
needs:
102+
- tag
103+
runs-on: ubuntu-20.04
104+
environment: release
105+
permissions:
106+
contents: read
107+
packages: write
108+
steps:
109+
- uses: actions/checkout@v3
110+
with:
111+
# in order to properly resolve the version from git
112+
fetch-depth: 0
113+
72114
- name: Bootstrap environment
73115
uses: ./.github/actions/bootstrap
74116

@@ -77,19 +119,31 @@ jobs:
77119
echo ${{ secrets.GITHUB_TOKEN }} | oras login ghcr.io --username ${{ github.actor }} --password-stdin
78120
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io --username ${{ github.actor }} --password-stdin
79121
80-
- name: Tag release
81-
run: |
82-
git tag ${{ github.event.inputs.version }}
83-
git push origin --tags
84-
env:
85-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
86-
87122
- name: Promote commit image to release
88123
run: |
89124
make ci-promote-release
90125
env:
91126
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92127

128+
release-github:
129+
needs:
130+
- tag
131+
runs-on: ubuntu-20.04
132+
environment: release
133+
permissions:
134+
contents: read
135+
packages: write
136+
issues: read
137+
pull-requests: read
138+
steps:
139+
- uses: actions/checkout@v3
140+
with:
141+
# in order to properly resolve the version from git
142+
fetch-depth: 0
143+
144+
- name: Bootstrap environment
145+
uses: ./.github/actions/bootstrap
146+
93147
- name: Create github release
94148
run: |
95149
make changelog

.github/workflows/validations.yaml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ jobs:
1515
runs-on: ubuntu-20.04
1616
permissions:
1717
contents: read
18-
# package write permission is needed for publishing commit images
19-
packages: write
2018
steps:
2119
- uses: actions/checkout@v3
2220
with:
@@ -39,11 +37,35 @@ jobs:
3937
- name: Build assets
4038
run: poetry run make build
4139

40+
Publish-PreProd:
41+
runs-on: ubuntu-20.04
42+
needs: [Validations]
43+
if: github.ref == 'refs/heads/main'
44+
permissions:
45+
contents: read
46+
# package write permission is needed for publishing commit images
47+
packages: write
48+
steps:
49+
- uses: actions/checkout@v3
50+
with:
51+
# in order to properly resolve the version from git
52+
fetch-depth: 0
53+
54+
- name: Bootstrap environment
55+
uses: ./.github/actions/bootstrap
56+
4257
- name: Login to ghcr.io
43-
if: github.ref == 'refs/heads/main'
4458
run: |
4559
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io --username ${{ github.actor }} --password-stdin
4660
61+
- name: Build assets
62+
run: poetry run make build
63+
4764
- name: Publish commit image
48-
if: github.ref == 'refs/heads/main'
4965
run: make ci-publish-commit
66+
67+
- name: Publish to test PyPI
68+
run: make ci-publish-testpypi
69+
env:
70+
# note: "..._TESTPYPI" suffix should match the name of the testpypi repository (see the Makefile target)
71+
POETRY_PYPI_TOKEN_TESTPYPI: ${{ secrets.TEST_PYPI_TOKEN }}

Makefile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ GRYPE_DB_PATH ?= ../grype-db
1212
CRANE = $(TEMP_DIR)/crane
1313
CHRONICLE = $(TEMP_DIR)/chronicle
1414
GLOW = $(TEMP_DIR)/glow
15+
PUBLISH_CMD = poetry publish --build -n
1516

1617
# Tool versions #################################
1718
CHRONICLE_VERSION = v0.6.0
@@ -123,8 +124,12 @@ unit: virtual-env-check ## Run unit tests
123124

124125
## Build-related targets #################################
125126

127+
.PHONY: check-build-deps
128+
check-build-deps:
129+
@poetry self show plugins | grep poetry-dynamic-versioning || echo "install poetry-dynamic-versioning plugin with 'poetry plugin add poetry-dynamic-versioning[plugin]'"
130+
126131
.PHONY: build
127-
build: ## Run build assets
132+
build: check-build-deps ## Run build assets
128133
git fetch --tags
129134
rm -rf dist
130135
poetry build
@@ -149,6 +154,15 @@ ci-promote-release: ci-check
149154
$(CRANE) tag $(IMAGE_NAME):$(COMMIT_TAG) $(PACKAGE_VERSION)
150155
$(CRANE) tag $(IMAGE_NAME):$(COMMIT_TAG) latest
151156

157+
.PHONY: ci-publish-testpypi
158+
ci-publish-testpypi: clean-dist check-build-deps
159+
poetry config repositories.testpypi https://test.pypi.org/legacy/
160+
$(PUBLISH_CMD) -r testpypi
161+
162+
.PHONY: ci-publish-pypi
163+
ci-publish-pypi: ci-check clean-dist check-build-deps
164+
$(PUBLISH_CMD)
165+
152166
.PHONY: changelog
153167
changelog:
154168
@$(CHRONICLE) -vvv -n . --version-file VERSION > CHANGELOG.md
@@ -159,6 +173,12 @@ release:
159173
@.github/scripts/trigger-release.sh
160174

161175

176+
## Cleanup #################################
177+
178+
.PHONY: clean-dist
179+
clean-dist:
180+
rm -rf dist
181+
162182
## Halp! #################################
163183

164184
.PHONY: help

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,18 @@ Supported data sources:
2020
With pip:
2121

2222
```bash
23-
pip install git+https://github.com/anchore/vunnel@main
24-
25-
# or use a git tag
26-
pip install git+https://github.com/anchore/[email protected]
23+
pip install vunnel
2724
```
2825

2926
With docker:
3027

3128
```bash
3229
docker run \
3330
--rm -it \
34-
-v $(pwd)/data:/data \ # keep the processed data on the host
35-
-v $(pwd)/.vunnel.yaml:/.vunnel.yaml # if you have a vunnel config
36-
ghcr.io/anchore/vunnel:latest # a git tag can be used as the version
37-
run nvd # arguments for vunnel
31+
-v $(pwd)/data:/data \
32+
-v $(pwd)/.vunnel.yaml:/.vunnel.yaml \
33+
ghcr.io/anchore/vunnel:latest \
34+
run nvd
3835
```
3936
Where:
4037
- the `data` volume keeps the processed data on the host

RELEASE.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ There are two times when assets are released:
88

99
- when a new commit reaches main:
1010
- a new `ghcr.io/anchore/vunnel:[GIT-COMMIT]` docker image is published
11+
- a build is published to the [testpypi project](https://test.pypi.org/project/vunnel/)
1112

1213
- when a release is triggered:
1314
- the commit on main is tagged with the given version
14-
- the existing commit-based image is additionally tagged as `ghcr.io/anchore/vunnel:[VERSION]`
15-
15+
- the existing commit-based image is additionally tagged as `ghcr.io/anchore/vunnel:[VERSION]` and `ghcr.io/anchore/vunnel:latest`
16+
- a build is published to the [pypi project](https://pypi.org/project/vunnel/)
1617

1718
## Creating a new release
1819

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ fail_under = 80
138138
[tool.poetry-dynamic-versioning]
139139
enable = true
140140
vcs = "git"
141-
metadata = true
141+
metadata = false
142142
style = "semver"
143143
dirty = true
144144

0 commit comments

Comments
 (0)