-
Notifications
You must be signed in to change notification settings - Fork 1
149 lines (128 loc) · 3.82 KB
/
hatch-build-and-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
name: Hatch Build and Publish
run-name: HATCH to PyPI by @${{ github.actor }}
on:
workflow_dispatch:
push:
tags:
- 'v*.*.*'
permissions:
contents: write
packages: write
id-token: write
jobs:
get-ref:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get current branch
id: check_step
run: |
raw=$(git branch -r --contains ${{ github.ref }})
if [[ -z "$raw" ]]; then
raw=$(git branch -r --contains ${{ github.sha }})
fi
if [[ -z "$raw" ]]; then
echo "No branch found for ${{ github.ref }} or ${{ github.sha }}."
echo "This is probably a tag push without a branch."
exit 1
fi
BRANCH=${raw##*/}
BRANCH=$(echo $BRANCH | base64 -w 0)
echo "BRANCH=$BRANCH" >> $GITHUB_OUTPUT
echo "Branch is $BRANCH."
outputs:
branch-name: ${{ steps.check_step.outputs.BRANCH }}
get-tag:
runs-on: ubuntu-latest
needs: get-ref
steps:
- name: Decode ref
id: decode_ref
run: |
name=${{ needs.get-ref.outputs.branch-name }}
name=$(echo $name | base64 -d)
echo "NAME=$name" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ env.NAME }}
fetch-depth: 0
- name: Set env
id: set-env
run: |
if [[ "${{ github.event_name }}" == "push" ]]; then
TAG=$(echo $GITHUB_REF | cut -d / -f 3)
echo "TAG=$TAG" >> $GITHUB_ENV
fi
outputs:
tag: ${{ env.TAG }}
deploy:
runs-on: ubuntu-latest
environment: release
needs:
- get-ref
- get-tag
steps:
- name: Decode ref
id: decode_ref
run: |
name=${{ needs.get-ref.outputs.branch-name }}
echo "Encoded ref is $name"
name=$(echo $name | base64 -d)
echo "Decoded ref is $name"
echo "REF=$name" >> $GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ env.REF }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install hatch
- name: Version bump
if : ${{ github.event_name != 'push' }}
run: |
cd panoptic_back
hatch version fix
echo "Version bumped"
- name: Version from tag
if : ${{ github.event_name == 'push' }}
run: |
TAG=${{ needs.get-tag.outputs.tag }}
echo "TAG=$TAG"
cd panoptic_back
hatch version $TAG
# && echo "Version set to $TAG" || echo "Version already exists" && exit 1
- name: Build package
run: |
cd panoptic_back
hatch build
- name: Move dist files
run: |
mkdir -p dist
mv panoptic_back/dist/* dist/
- name: Publish package
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }} # PYPI_API_TOKEN
# repository-url: https://test.pypi.org/legacy/ # uncomment for test.pypi.org
- name: Update the about.py file
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "Update about.py file"
file_pattern: "panoptic_back/panoptic/__init__.py"
status_options: '--untracked-files=no'
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ env.REF }}