-
Notifications
You must be signed in to change notification settings - Fork 24
95 lines (83 loc) · 3 KB
/
publish.yaml
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
name: Publish
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
packages: write
steps:
- uses: actions/checkout@v3
- name: Set up PDM
uses: pdm-project/setup-pdm@v3
with:
python-version: '3.10'
# Publish to PyPI
- name: Publish to PyPI
run: pdm publish
- name: Bump version
run: |
TAG_NAME=${{ github.ref }}
CURRENT_RECAP_VERSION=${TAG_NAME#refs/tags/}
NEW_RECAP_VERSION=$(echo $CURRENT_RECAP_VERSION | awk -F. '{$NF++; print $1"."$2"."$NF}')
echo "CURRENT_RECAP_VERSION=$CURRENT_RECAP_VERSION" >> $GITHUB_ENV
echo "NEW_RECAP_VERSION=$NEW_RECAP_VERSION" >> $GITHUB_ENV
sed -i "s/^version = \"\([0-9]\+\)\.\([0-9]\+\)\.\([0-9]\+\)\"$/version = \"$NEW_RECAP_VERSION\"/" pyproject.toml
- name: Commit version bump
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: Bump version ${{ env.NEW_RECAP_VERSION }}
file_pattern: pyproject.toml
# Wait for PyPI to update
- name: Wait for PyPI to update
run: |
PACKAGE_VERSION=${{ env.CURRENT_RECAP_VERSION }}
MAX_ATTEMPTS=12
ATTEMPT_COUNT=0
SLEEP_SECONDS=10
while [ $ATTEMPT_COUNT -lt $MAX_ATTEMPTS ]; do
# `true` because `pip index` returns a non-zero exit code when no package is found,
# which causes the script to fail.
AVAILABLE_VERSIONS=$(pip --no-cache-dir index --ignore-requires-python versions recap-core) || true
if [[ $AVAILABLE_VERSIONS =~ "recap-core ($PACKAGE_VERSION)" ]]; then
break
else
echo "Package version ${PACKAGE_VERSION} is not yet available on PyPI."
echo "Retrying in $SLEEP_SECONDS seconds."
sleep $SLEEP_SECONDS
((ATTEMPT_COUNT++))
fi
done
if [ $ATTEMPT_COUNT -eq $MAX_ATTEMPTS ]; then
echo "No package available after $MAX_ATTEMPTS. Exiting."
exit 1
fi
# Publish Docker image
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
RECAP_VERSION=${{ env.CURRENT_RECAP_VERSION }}