-
Notifications
You must be signed in to change notification settings - Fork 13
113 lines (93 loc) · 3.91 KB
/
build_and_release.yaml
File metadata and controls
113 lines (93 loc) · 3.91 KB
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
####################################################################################
## This workflow automates the build and release process for Valispace ##
## Python API. Triggered on pushes to the master branch, the workflow ##
## sets up Python environments for multiple versions (3.9), ##
## displays the Python version, installs Twine for package management, builds ##
## the project using python setup.py bdist_wheel, and releases the distribution ##
## files to PyPI using Twine. ##
####################################################################################
name: Create new Valispace Python API release
on:
push:
branches:
- master
jobs:
pre_checks:
runs-on: ubuntu-latest
# Define variables to share across jobs
outputs:
current_version: ${{ steps.get_version.outputs.current_version}}
skip_action: ${{ steps.check_setup.outputs.skip_action}}
steps:
# Project checkout
- name: Checkout project
uses: actions/checkout@v4
# Get Valispace Python API version
- name: Get version
id: get_version
run: |
version=$(grep --extended-regexp "version" "setup.py" | awk -F"'" '{print $2}')
echo "current_version=$version" >> "$GITHUB_OUTPUT"
# Check if version present on master branch is the same as latest tag
- name: Check if setup.py was updated
id: check_setup
run: |
latest_tag=$(git describe --tags --abbrev=0 --always)
current_version=${{ steps.get_version.outputs.current_version }}
echo "Current version: $current_version"
echo "Latest tag: $latest_tag"
if [ "$current_version" == "$latest_tag" ]; then
echo "Setup.py version is equal to the latest Git tag. Action will be terminated."
echo "skip_action=True" >> "$GITHUB_OUTPUT"
else
echo "Setup.py version is different from the latest Git tag. Action will continue."
echo "skip_action=False" >> "$GITHUB_OUTPUT"
fi
shell: bash
# Execute Python API Build and deploy if version present on master branch is different from latest tag
python_api_build_and_deploy:
needs: pre_checks
if: needs.pre_checks.outputs.skip_action == 'false'
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9"]
steps:
# Project checkout
- name: Checkout project
uses: actions/checkout@v4
# Use python versions defined on strategy.matrix
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
# Print python version currently in use
- name: Display Python version
run: python -c "import sys; print(sys.version)"
# Install dependecies used to build Valispace Python API
- name: Install Dependencies
run: |
pip install twine
pip install wheel
# Build Valispace Python API
- name: Build project
run: python setup.py bdist_wheel
#Upload new version to twine
- name: Release API on PyPi
env:
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
run: twine upload dist/*
# Create new release using the current version
- name: 'Create new release in GitHub'
id: release
uses: ncipollo/release-action@v1
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
with:
commit: '${{ steps.setup.outputs.branch }}'
tag: '${{ needs.pre_checks.outputs.current_version }}'
name: '${{ needs.pre_checks.outputs.current_version }}'
generateReleaseNotes: true
allowUpdates: true
prerelease: false