-
Notifications
You must be signed in to change notification settings - Fork 35
88 lines (75 loc) · 3.01 KB
/
build_and_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
name: Build and publish
on:
pull_request:
workflow_dispatch:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Get the master branch (for checks)
uses: actions/checkout@v4
with:
ref: 'refs/heads/master'
- uses: actions/checkout@v4
- name: Set up Python 3.7
uses: actions/setup-python@v5
with:
python-version: 3.7
- name: Cache pip
uses: actions/cache@v4
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('NuRadioMC/test/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install poetry
run: |
python -m pip install --upgrade pip
pip install poetry
# poetry recommends using curl to install - probably doesn't make a difference though?
- name: Build NuRadioMC # let's always build - maybe this will occasionally catch errors
run: poetry build
- name: Check if version is updated
if: ${{ github.ref != 'refs/heads/master'}} # don't run if we're on master
run: |
git checkout master
export master_version=$(poetry version)
git checkout $GITHUB_SHA
if [ "$master_version" = "$(poetry version)" ]
then
echo Version number is the same as existing release. Please update the version number!
exit 1
fi
- name: Publish distribution 📦 to Test PyPI
if: ${{ github.ref == 'refs/heads/master'}} # only runs if the push is to master
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
- name: Publish distribution 📦 to PyPI
if: ${{ github.ref == 'refs/heads/master'}} # only runs if the push is to master
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
- name: Make tag and release
if: ${{ github.ref == 'refs/heads/master'}} # only runs if the push is to master
env:
GH_TOKEN: ${{ github.token}}
run: |
export VERSION_NEW="$(poetry version -s)"
export NEW_TAG=v$VERSION_NEW
git tag $NEW_TAG -m "$NEW_TAG release"
git push origin $NEW_TAG
# we want to include the changelog since the last release
# First, we use gh release and some regex to get the latest tag
export LATEST_TAG=$(gh release list | sed -rn 's/.*Latest\s*(\S+).*/\1/p')
# Next, we use some more regex to select
# the section of the changelog between the new and latest versions:
git diff --output-indicator-new=\| $LATEST_TAG $NEW_TAG changelog.txt | sed -rn "/^\|.*$VERSION_NEW/,/^[^|]/{s/\|//p}" | sed -n "2,\$p" > /tmp/changelog_$NEW_TAG.md
gh release create $NEW_TAG --notes-file /tmp/changelog_$NEW_TAG.md --generate-notes