-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (99 loc) · 4.34 KB
/
attempt-release.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
name: Attempt release
on:
# We want to release from the master branch.
# Assuming that the actual work is done in branches, triggering the workflow
# on pushes will ensure that every merged branch can potentially create a new
# release
push:
branches: ["master"]
tags: ["v*"]
jobs:
create-version-tag:
runs-on: ubuntu-latest
environment:
# These two are needed by the publish to pypi action
# https://github.com/marketplace/actions/pypi-publish
name: pypi
url: https://pypi.org/p/semv
permissions:
contents: write # needed for pushing tags or creating releases
id-token: write # needed for publish to pypi action
steps:
- uses: actions/checkout@v3
with:
# IMPORTANT: semv will look at our commit history
# we therefore need to fetch all commits, which is done here by
# setting fetch-depth to 0. See here for more details on the checkout action:
# https://github.com/actions/checkout
fetch-depth: 0
- name: Setup python 3.8
uses: actions/setup-python@v4
with:
# Why python3.8? It's the earliest python version that we support
python-version: "3.8"
- name: Install dependencies
run: |
pip install --upgrade pip
pip install tox
pip install -e .
- name: Setup git and list existing tags
run: |
git config user.name "ci"
git config user.email "ci"
git config --global init.defaultBranch master
git tag
- name: Run tests
# This could in principle be skipped if we were strict about only
# merging branches that pass all tests. Ensures that accidental merge
# conflicts don't break released package
run: tox
- name: Print version
# This is the key step. By setting an id, we can read the output in later steps
id: print-version
# We only want to run this step if we are on a pushed commit -- it will
# give an exit status of 1 if we are already on a version tag.
if: startsWith(github.ref, 'refs/heads/')
# In order to be able to read the output in later steps, we need to
# write something that looks like a variable definitionn to the
# environment variable GITHUB_OUTPUT
run: echo "semv-out=$(semv)" >> $GITHUB_OUTPUT
# NOTE: This step doesn't check the statuscode of semv (non-zero if no new version)
- name: Create changelog
run: |
semv --changelog > ${{ github.workspace }}-CHANGELOG.md
cat ${{ github.workspace }}-CHANGELOG.md
- uses: thejeff77/action-push-tag@v1.0.0
# Only run this step if this is a pushed commit and not a tag
if: startsWith(github.ref, 'refs/heads/')
with:
# Here we refer to the variable that we just wrote the the GITHUB_OUTPUT variable
tag: ${{ steps.print-version.outputs.semv-out }}
# NOTE: This step will fail if semv-out is empty (i.e. there was no
# new version) and thus all following steps won't run either.
- name: Set output
id: set_output
# NOTE: We can unconditionally set should_publish=true here, because we
# wouldn't even reach this point if one of the previous points had
# failed.
run: echo "set-output name=should_publish::true"
- name: Setup git and list existing tags
run: |
git config user.name "ci"
git config user.email "ci"
git tag
echo $${{ steps.set_output.outputs.should_publish }}
# The following steps should be more or less standard python package publishing
# Feel free to omit the github release.
- name: Create github release
uses: softprops/action-gh-release@v1
if: ${{ steps.set_output.outputs.should_publish }} == 'true'
with:
tag_name: ${{ steps.print-version.outputs.semv-out }}
body_path: ${{ github.workspace }}-CHANGELOG.md
generate_release_notes: false # do not generate release notes, we generated them with semv
- name: Build package
if: ${{ steps.set_output.outputs.should_publish }} == 'true'
run: tox -e build
- name: Publish to pypi
if: ${{ steps.set_output.outputs.should_publish }} == 'true'
uses: pypa/gh-action-pypi-publish@release/v1