-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
159 lines (139 loc) · 4.7 KB
/
action.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: 'Setup blogc environment'
description: 'Setup a blogc environment and add it to the PATH'
inputs:
blogc-version:
description: 'The blogc version to setup. Must be a version, a Git reference or LATEST for latest stable release'
required: true
default: 'LATEST'
outputs:
blogc-version:
description: 'The installed blogc version. Useful when given LATEST or some Git reference as input.'
value: ${{ steps.version.outputs.version }}
cache-hit:
description: 'A boolean value to indicate if a cache was hit'
value: ${{ steps.cache-restore.outputs.cache-hit }}
runs:
using: "composite"
steps:
- name: Check runner OS
if: ${{ runner.os != 'Linux' }}
run: |
echo "::error title=Error hint::The setup-blogc action supports only linux"
exit 1
shell: bash
- name: Resolve git reference
id: gitref
run: |
ref="${{ inputs.blogc-version }}"
if [[ "x${ref}" = xLATEST ]]; then
ref="$(
git \
-c versionsort.suffix=- \
ls-remote \
--exit-code \
--refs \
--sort=version:refname \
--tags \
https://github.com/blogc/blogc.git \
"v*.*.*" \
| cut -d/ -f3- \
| tail -n 1
)"
fi
if [[ "${ref}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
ref="v${ref}"
fi
if git ls-remote --exit-code https://github.com/blogc/blogc.git "${ref}" > /dev/null; then
echo "ref=$(git ls-remote https://github.com/blogc/blogc.git "${ref}" | cut -d$'\t' -f1)" >> $GITHUB_OUTPUT
exit 0
fi
# assume that ref is a hash already, pass it directly to actions/checkout
echo "ref=${ref}" >> $GITHUB_OUTPUT
shell: bash
- name: Restore blogc build from cache, if exists
id: cache-restore
uses: actions/cache/restore@v4
with:
path: /opt/blogc
key: Linux-build-blogc-${{ steps.gitref.outputs.ref }}
- name: Check out code
if: steps.cache-restore.outputs.cache-hit != 'true'
uses: actions/checkout@v4
with:
repository: blogc/blogc
ref: ${{ steps.gitref.outputs.ref }}
path: .blogc-build
fetch-depth: 0
- name: Detect build system
if: steps.cache-restore.outputs.cache-hit != 'true'
id: build-system
working-directory: .blogc-build
run: |
if [[ -e "CMakeLists.txt" ]]; then
echo "name=cmake" >> $GITHUB_OUTPUT
else
echo "name=autotools" >> $GITHUB_OUTPUT
fi
shell: bash
- name: Install dependencies (autotools)
if: steps.cache-restore.outputs.cache-hit != 'true' && steps.build-system.outputs.name == 'autotools'
run: sudo apt install -y ronn
shell: bash
- name: Install dependencies (cmake)
if: steps.cache-restore.outputs.cache-hit != 'true' && steps.build-system.outputs.name == 'cmake'
run: sudo apt install -y cmake ninja-build
shell: bash
- name: Build blogc (autotools)
if: steps.cache-restore.outputs.cache-hit != 'true' && steps.build-system.outputs.name == 'autotools'
working-directory: .blogc-build
run: |
./autogen.sh
./configure \
"CFLAGS=-Wall -g -O3" \
--prefix=/opt/blogc \
--disable-silent-rules \
--disable-valgrind \
--disable-tests \
--enable-make
make -j$(nproc)
sudo make install
shell: bash
- name: Build blogc (cmake)
if: steps.cache-restore.outputs.cache-hit != 'true' && steps.build-system.outputs.name == 'cmake'
working-directory: .blogc-build
run: |
cmake \
-B build \
-S . \
-DCMAKE_INSTALL_PREFIX=/opt/blogc \
-DBUILD_BLOGC_MAKE=ON \
-G Ninja
cmake \
--build build \
--config Release
sudo cmake \
--build build \
--config Release \
--target install
shell: bash
- name: Delete blogc build directory
if: steps.cache-restore.outputs.cache-hit != 'true'
run: rm -rf .blogc-build
shell: bash
- name: Add blogc to PATH
run: echo "/opt/blogc/bin" >> $GITHUB_PATH
shell: bash
- name: Check if blogc works
id: version
run: |
blogc -v
blogc-make -v
echo "version=$(blogc -v | cut -d' ' -f2)" >> $GITHUB_OUTPUT
shell: bash
- name: Save blogc build to cache, if needed
if: steps.cache-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
id: cache-save
with:
path: /opt/blogc
key: Linux-build-blogc-${{ steps.gitref.outputs.ref }}