Repository navigation
178 lines (172 loc) · 6.3 KB
/
Copy pathc-cpp-release-template.yml
File metadata and controls
178 lines (172 loc) · 6.3 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# SPDX-FileCopyrightText: Copyright (C) 2025 Fabrício Barros Cabral
# SPDX-License-Identifier: MIT
---
# yamllint disable rule:line-length
name: c-cpp-release-template
'on':
workflow_call:
inputs:
working-directory:
description: "Set the working directory"
required: false
default: "."
type: string
secrets:
GH_TOKEN:
description: 'GitHub token'
required: true
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: 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"
c-cpp-macos-build-template:
runs-on: macos-15
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
persist-credentials: false
- name: Detect working directory
id: detect
run: |
if [[ -d c-cpp ]]; then
echo "dir=c-cpp" >> "${GITHUB_OUTPUT}"
else
echo "dir=." >> "${GITHUB_OUTPUT}"
fi
- 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"
c-cpp-release-template:
runs-on: ubuntu-24.04
needs: [c-cpp-linux-build-template, c-cpp-macos-build-template]
permissions:
contents: write
steps:
- name: Download Linux artifacts
uses: actions/download-artifact@v5
with:
name: linux-dist
path: dist
- name: Download macOS artifacts
uses: actions/download-artifact@v5
with:
name: macos-dist
path: dist
- name: Set release tag
id: tag
run: |
# Detects which tag triggered the build
echo "tag=${GITHUB_REF##*/}" >> "${GITHUB_OUTPUT}"
- name: Release artifacts
uses: softprops/action-gh-release@19cd0bcd2b95a5f9e0aab8377b3cae33e51c2234
with:
tag_name: ${{ steps.tag.outputs.tag }}
files: dist/*.tar.gz
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}