-
Notifications
You must be signed in to change notification settings - Fork 76
136 lines (132 loc) · 5 KB
/
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# `release` workflow configuration
#
# This workflow is triggered when a release branch is merged into the main
# branch. It automates the process of creating a package and releasing it to
# GitHub and PyPI.
#
# Workflow steps:
# 0. A release branch named release/[TAG] is merged into main via a pull
# request.
# 1. `tagging` job runs:
# - A branch named [TAG] is created
# 2. `release` job runs:
# - Create a PyPI package
# - Create a release on GitHub
# - Release the package on PyPI
# 3. `delete-branch` job runs:
# - Delete the release branch
name: Release
on:
pull_request:
branches:
- main
types:
- closed
jobs:
tagging:
runs-on: ubuntu-latest
if: |
github.event.pull_request.merged == true
&& startsWith(github.event.pull_request.head.ref, 'release/')
steps:
- name: Determine the tag name based on the branch name
id: get_version
run: |
echo "TAG=$(echo $BRANCH | cut -d / -f 2)" >> $GITHUB_OUTPUT
env:
BRANCH: ${{ github.event.pull_request.head.ref }}
- name: Print the tag name for debugging
run: echo "${{ steps.get_version.outputs.TAG }}"
- uses: actions/checkout@v2
- name: Create a corresponding tag branch
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git fetch origin ${{ github.event.pull_request.head.ref }}
git checkout main
git tag -a `echo '${{ github.event.pull_request.head.ref }}' | sed 's/release\///'` -m " "
git push origin `echo '${{ github.event.pull_request.head.ref }}' | sed 's/release\///'`
release:
name: release
runs-on: ubuntu-latest
needs: [tagging]
strategy:
# NOTE: Only one version should be set (It is aimed to reduce the cost to change versions)
matrix:
python-version: ['3.9']
steps:
- name: Determine the tag name based on the branch name
id: get_version
run: |
echo "TAG=$(echo $BRANCH | cut -d / -f 2)" >> $GITHUB_OUTPUT
env:
BRANCH: ${{ github.event.pull_request.head.ref }}
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install poetry
poetry install
- name: Build the package
run: |
poetry build
- name: Push a release to GitHub. At the beginning of release, the body of pull request is shown.
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.get_version.outputs.TAG }}
release_name: ${{ steps.get_version.outputs.TAG }}
draft: false
prerelease: false
body: |
${{ github.event.pull_request.body }}
This release is automatically generated.
Please see the pull request for more details.
[${{ github.event.pull_request.html_url }}](${{ github.event.pull_request.html_url }})
- name: Generate checksum for all elements in dist directory
run: |
cd dist; sha256sum * > checksums.txt; cd -
- name: Attach an archive of source files to the release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/pfhedge-${{ steps.get_version.outputs.TAG }}.tar.gz
asset_name: pfhedge-${{ steps.get_version.outputs.TAG }}.tar.gz
asset_content_type: application/gzip
- name: Attach a Python wheel to the release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/pfhedge-${{ steps.get_version.outputs.TAG }}-py3-none-any.whl
asset_name: pfhedge-${{ steps.get_version.outputs.TAG }}-py3-none-any.whl
asset_content_type: application/x-pywheel+zip
- name: Attach the checksum of the files to the release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist/checksums.txt
asset_name: pfhedge-${{ steps.get_version.outputs.TAG }}-checksums.txt
asset_content_type: text/plain
- name: Release the version to PyPI
run: |
poetry publish --username __token__ --password ${{ secrets.PYPI_TOKEN }}
delete-branch:
runs-on: ubuntu-latest
needs: [tagging, release]
steps:
- uses: actions/checkout@v2
- name: Delete the release branch
run: |
git push --delete origin ${{ github.event.pull_request.head.ref }}