-
Notifications
You must be signed in to change notification settings - Fork 10
154 lines (123 loc) · 4.87 KB
/
publish.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
# From https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
name: "Publish"
on:
push:
pull_request:
branches:
- main
jobs:
tests:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install devbox
uses: jetpack-io/devbox-install-action@v0.11.0
- name: Run linting
run: devbox run lint
- name: Check code formatting
run: devbox run format-check
- name: Run type checks
run: devbox run typecheck
- name: Run tests
run: devbox run test
env:
# Unit tests actually run against the GH API for 'real integration testing',
# and providing a token will increase the otherwise too-low rate limit.
# The `GITHUB_TOKEN` failed (https://github.com/alexpovel/ancv/actions/runs/4093416643/jobs/7063406195):
#
# body = b'{"message":"Resource not accessible by integration","documentation_url":"https://docs.github.com/rest/reference/gists#list-gists-for-a-user"}'
#
# So use a personal token.
GH_TOKEN: ${{ secrets.GH_PERMISSIONLESS_FGAT }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
# Docs say a token isn't required for public GitHub repositories using GH
# Actions, but it didn't work and failed with:
#
# [2022-08-08T19:50:41.725Z] ['error'] There was an error running the
# uploader: Error uploading to https://codecov.io: Error: There was an error
# fetching the storage URL during POST: 404 - {'detail':
# ErrorDetail(string='Unable to locate build via Github Actions API. Please
# upload with the Codecov repository upload token to resolve issue.',
# code='not_found')}
#
# See also: https://github.com/alexpovel/ancv/runs/7733256776?check_suite_focus=true#step:7:37
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
release-please:
name: Execute release chores
runs-on: ubuntu-latest
needs: tests
outputs:
created: ${{ steps.release.outputs.release_created }}
tag_name: ${{ steps.release.outputs.tag_name }}
steps:
# https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/making-authenticated-api-requests-with-a-github-app-in-a-github-actions-workflow
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: googleapis/release-please-action@v4
id: release
with:
# Token needs: `contents: write`, `pull-requests: write`
token: ${{ steps.app-token.outputs.token }}
publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: release-please
if: ${{ needs.release-please.outputs.created }}
# https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/
environment: pypi
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Install devbox
uses: jetpack-io/devbox-install-action@v0.11.0
with:
enable-cache: true
- name: Build package
run: devbox run uv build
- name: Publish package
uses: pypa/gh-action-pypi-publish@v1.10.2
build-and-push-image:
name: Build Docker image and push to GitHub Container Registry
runs-on: ubuntu-latest
needs: release-please
if: ${{ needs.release-please.outputs.created }}
environment: container-registry
permissions:
contents: read
packages: write
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to the container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=semver,value=${{ needs.release-please.outputs.tag_name }},pattern={{version}}
type=semver,value=${{ needs.release-please.outputs.tag_name }},pattern={{major}}.{{minor}}
type=semver,value=${{ needs.release-please.outputs.tag_name }},pattern={{major}},enable=${{ !startsWith(needs.release-please.outputs.tag_name, 'v0.') }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}