Repository navigation
153 lines (147 loc) · 5.65 KB
/
Copy pathc-cpp-build-template.yml
File metadata and controls
153 lines (147 loc) · 5.65 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# SPDX-FileCopyrightText: Copyright (C) 2025 Fabrício Barros Cabral
# SPDX-License-Identifier: MIT
---
# yamllint disable rule:line-length
name: c-cpp-build-template
'on':
workflow_call:
inputs:
working-directory:
description: "Set the working directory"
required: false
default: "."
type: string
defaults:
run:
shell: bash -xeuo pipefail {0}
permissions:
contents: read
jobs:
c-cpp-linux-build-template:
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Configure APT cache
uses: actions/cache@v4
with:
path: /var/cache/apt/archives
key: ${{ runner.os }}-apt-${{ hashFiles('**/apt-packages.txt') }}
restore-keys: ${{ runner.os }}-apt-
- name: Install dependencies
working-directory: ${{ inputs.working-directory }}
run: |
if [[ -s apt-packages.txt ]]; then
sudo apt-get update
xargs sudo apt-get install -y \
--no-install-recommends < apt-packages.txt
fi
- name: Configure and build
working-directory: ${{ inputs.working-directory }}
run: |
[[ -x ./autogen.sh ]] && ./autogen.sh
[[ -x ./configure ]] && ./configure
[[ -s Makefile ]] || {
echo "I couldn't find an autogen.sh, configure, or Makefile."
echo "Please check your files."
exit 1
}
make
- name: Get properties from configure.ac
working-directory: ${{ inputs.working-directory }}
id: props
run: |
name="$(sed -n 's/AC_INIT(\[\([^]]*\)\],.*/\1/p' configure.ac)"
echo "name=${name}" >> "${GITHUB_OUTPUT}"
version="$(sed -n 's/AC_INIT(\[[^]]*\], \[\([^]]*\)\], \[[^]]*\])/\1/p' configure.ac)"
echo "version=${version}" >> "${GITHUB_OUTPUT}"
- name: Create source package
working-directory: ${{ inputs.working-directory }}
run: |
make dist
- name: Create Linux binary package
working-directory: ${{ inputs.working-directory }}
run: |
make binary-dist
- name: Prepare packages to distribution
working-directory: ${{ inputs.working-directory }}
run: |
# Sanitize variables for security purposes
safe_name="$(echo "${{ steps.props.outputs.name }}" | tr -cd '[:alnum:]._-' )"
safe_version="$(echo "${{ steps.props.outputs.version }}" | tr -cd '[:alnum:]._-' )"
# Check if variables are empty
[[ -z "$safe_name" ]] && { echo "Invalid name"; exit 1; }
[[ -z "$safe_version" ]] && { echo "Invalid version"; exit 1; }
# Check if files exists
src="${safe_name}-${safe_version}.tar.gz"
bin="${safe_name}-${safe_version}-bin.tar.gz"
[[ -f "$src" ]] || { echo "File '${src}' not found"; exit 1; }
[[ -f "$bin" ]] || { echo "File '${bin}' not found"; exit 1; }
# Move files
mkdir -p dist
mv "${src}" dist/
mv "${bin}" "dist/${safe_name}-${safe_version}-linux.tar.gz"
- name: Upload Linux artifacts
uses: actions/upload-artifact@v4
with:
name: linux-dist
path: "${{ inputs.working-directory }}/dist/*.tar.gz"
c-cpp-macos-build-template:
runs-on: macos-15
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Install dependencies
working-directory: ${{ inputs.working-directory }}
run: |
if [[ -s brew-packages.txt ]]; then
brew update
xargs brew install < brew-packages.txt
fi
- name: Configure and build
working-directory: ${{ inputs.working-directory }}
run: |
[[ -x ./autogen.sh ]] && ./autogen.sh
[[ -x ./configure ]] && ./configure
[[ -s Makefile ]] || {
echo "I couldn't find an autogen.sh, configure, or Makefile."
echo "Please check your files."
exit 1
}
make
- name: Get properties from configure.ac
working-directory: ${{ inputs.working-directory }}
id: props
run: |
name="$(sed -n 's/AC_INIT(\[\([^]]*\)\],.*/\1/p' configure.ac)"
echo "name=${name}" >> "${GITHUB_OUTPUT}"
version="$(sed -n 's/AC_INIT(\[[^]]*\], \[\([^]]*\)\], \[[^]]*\])/\1/p' configure.ac)"
echo "version=${version}" >> "${GITHUB_OUTPUT}"
- name: Create macOS binary package
working-directory: ${{ inputs.working-directory }}
run: |
make binary-dist
- name: Prepare package to distribution
working-directory: ${{ inputs.working-directory }}
run: |
# Sanitize variables for security purposes
safe_name="$(echo "${{ steps.props.outputs.name }}" | tr -cd '[:alnum:]._-' )"
safe_version="$(echo "${{ steps.props.outputs.version }}" | tr -cd '[:alnum:]._-' )"
# Check if variables are empty
[[ -z "$safe_name" ]] && { echo "Invalid name"; exit 1; }
[[ -z "$safe_version" ]] && { echo "Invalid version"; exit 1; }
# Check if file exist
bin="${safe_name}-${safe_version}-bin.tar.gz"
[[ -f "$bin" ]] || { echo "File '${bin}' not found"; exit 1; }
# Move file
mkdir -p dist
mv "${bin}" dist/"${safe_name}-${safe_version}-macos.tar.gz"
- name: Upload macOS artifacts
uses: actions/upload-artifact@v4
with:
name: macos-dist
path: "${{ inputs.working-directory }}/dist/*.tar.gz"