This repository was archived by the owner on Dec 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (118 loc) · 4.17 KB
/
cd.yml
File metadata and controls
129 lines (118 loc) · 4.17 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: "CD"
on:
push:
branches:
- "main"
env:
# Use latest stable version.
GO_VERSION: "stable"
PY_VERSION: "3.12"
PY_DIST_DIRECTORY: "whl"
jobs:
update-version:
name: "Create git tag"
runs-on: ubuntu-latest
outputs:
# Semantic version.
from-config: ${{ steps.extract.outputs.version }}
# "v" + Semantic version.
tag: ${{ steps.tag.outputs.new }}
steps:
- uses: actions/checkout@v4
- name: "Extract version from config file"
id: extract
# Extract the string value of the constant "Version" from the .go file.
run: |
v=$(grep -oP 'Version\s*=\s*"\K[^"]+' fext/config/config.go)
echo "version=$v" >> "$GITHUB_OUTPUT"
- name: "Setup git config"
# Inside the container, git config is empty,
# so we fill it similarly to the action initiator.
run: |
latest_commit=$(git log -1 --pretty=format:"%an|%ae")
IFS='|' read -r author_name author_email <<< "$latest_commit"
git config --global user.email "$author_email"
git config --global user.name "$author_name"
- name: "Create tag"
id: tag
# Add a new tag to Git, pulled from the config.
# The authorship goes to the initiator of the latest commit.
run: |
tag="v${{ steps.extract.outputs.version }}"
current_date=$(date +"%d %B %Y")
git tag -a "$tag" -m "Release $tag of $current_date"
git push origin "$tag"
echo "new=$tag" >> "$GITHUB_OUTPUT"
package:
name: "Build and package"
runs-on: ${{ matrix.os }}
needs:
- update-version
strategy:
matrix:
include:
- os: ubuntu-latest
exe_file: "fext"
platform: "linux"
platform_tag: "manylinux_2_35_x86_64"
- os: windows-latest
exe_file: "fext.exe"
platform: "windows"
platform_tag: "win_amd64"
steps:
# Prepare environment.
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PY_VERSION }}
check-latest: true
# Compile into binary file.
- name: "Build application"
run: cd fext && go build -o "dist/${{ matrix.exe_file }}"
# Package into wheel file.
- name: "Packaging application"
run: make build
env:
FEXT_PLATFORM_TAG: ${{ matrix.platform_tag }}
FEXT_VERSION: ${{ needs.update-version.outputs.from-config }}
FEXT_EXE_FILE: "fext/dist/${{ matrix.exe_file }}"
# This step blocks the execution of the package publication job,
# ensuring that we publish packages for ALL specified platforms.
# If an error occurs within this job, the publication won't be executed.
- name: "Transfer package to the next job"
uses: actions/upload-artifact@v4
with:
# Artifact doesn't support adding files to an existing storage,
# so it creates a separate one for each platform.
name: "pkg-${{ matrix.platform }}"
# the Make script saves the packaged application into this directory
# located within a $GITHUB_WORKSPACE.
path: ${{ env.PY_DIST_DIRECTORY }}
publish:
name: "Upload to the GitHub release"
runs-on: ubuntu-latest
needs:
- update-version
- package
steps:
# Duplicate is necessary to ensure the correctness of execution steps.
- name: "Download linux package"
uses: actions/download-artifact@v4
with:
name: "pkg-linux"
path: ${{ env.PY_DIST_DIRECTORY }}
- name: "Download windows package"
uses: actions/download-artifact@v4
with:
name: "pkg-windows"
path: ${{ env.PY_DIST_DIRECTORY }}
# Upload all packaged files to the corresponding release on GitHub.
- name: "Upload packages into release"
uses: svenstaro/upload-release-action@v2
with:
file: "${{ env.PY_DIST_DIRECTORY }}/*"
file_glob: true
tag: ${{ needs.update-version.outputs.tag }}