-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
170 lines (170 loc) · 6.44 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
160
161
162
163
164
165
166
167
168
169
170
name: 'debianise'
description: 'Builds a debian package from sources in a github repository'
inputs:
path:
description: 'Path to the checked out sources to build'
required: false
default: ''
install_build_depends:
description: 'Install packages listed in Build-Depends prior to build'
required: true
default: true
additional_build_depends:
description: 'Additional packages to install prior to build'
required: false
default: ''
additional_archive:
description: 'Path to additional *.tar.gz file to extract prior to build'
required: false
default: ''
pre_build_cmd:
description: 'Additional command to execute before build'
required: false
default: ''
package:
description: 'Package name if different from repository_name'
required: false
default: '${GITHUB_REPOSITORY##*/}'
version:
description: 'Version to build'
required: false
default: ''
create_changelog:
description: 'Create changelog based on git commit entries'
required: false
default: true
release_name:
description: 'Value to set to release_name on output'
required: false
default: '${PACKAGE}_${DCH_VER}'
tag_name:
description: 'Value to set to tag_name on output'
required: false
default: '${DCH_VER//\~/.}'
debug:
description: 'Display commands to they are executed'
required: false
default: true
outputs:
files:
value: ${{ steps.vars.outputs.files }}
release_name:
value: ${{ steps.vars.outputs.release_name }}
tag_name:
value: ${{ steps.vars.outputs.tag_name }}
runs:
using: "composite"
steps:
- name: Set variables
shell: bash
run: |
[ -z ${{ inputs.debug }} ] || set -x
case "${{ inputs.debug }}" in
yes|true)
debug='x'
;;
esac
BUILD_PATH=${{ inputs.path }}
[ -z "${BUILD_PATH}" ] || cd "${BUILD_PATH}"
case "${{ inputs.install_build_depends }}" in
yes|true)
BUILD_DEPENDS="$(grep -Po '(?<=Build-Depends:).*' debian/control | egrep -o '[a-zA-Z][a-zA-Z0-9+-]+' | tr '\n' ' ')"
;;
esac
BUILD_DEPENDS="${BUILD_DEPENDS} ${{ inputs.additional_build_depends }}"
CREATE_CHANGELOG=${{ inputs.create_changelog }}
PACKAGE=${{ inputs.package }}
PACKAGE=${PACKAGE//_/-}
PACKAGE=${PACKAGE,,}
VERSION=${{ inputs.version }}
for n in debug BUILD_DEPENDS BUILD_PATH CREATE_CHANGELOG PACKAGE VERSION; do
typeset -n v=${n}
echo "${n}=${v}"
done >> $GITHUB_ENV
- name: Build package
run: |
[ -z ${{ env.debug }} ] || set -x
[ -z "${BUILD_PATH}" ] || cd "${BUILD_PATH}"
[ -z ${{ inputs.additional_archive }} ] || tar -xzvf "${{ inputs.additional_archive }}"
[ -f debian/control ] || exit 1
sudo apt-get update
sudo apt-get install -y --no-install-suggests build-essential debhelper devscripts dh-exec ${BUILD_DEPENDS}
case "${{ inputs.install_build_depends }}" in
yes|true)
dpkg-checkbuilddeps 2>&1 \
| sed -E 's| \([^)]+\)||g' \
| ( grep -Po 'dependencies: \K.*' || true ) \
| xargs -r sudo apt-get install -y
;;
esac
sudo apt-get clean
case "${CREATE_CHANGELOG}" in
yes|true)
[ -d debian ] || mkdir debian
[ ! -f debian/changelog ] || rm debian/changelog
for ifs in \^ \~ \! \#; do
git log --format=%b:%B | grep -Fq "${ifs}" || break;
done
ver_date_sha=$(git log \
--format=tformat:%ad${ifs}%h${ifs}%aN${ifs}%aE${ifs}%f${ifs}%-aD${ifs}%D \
--date=format:%Y%m%d --reverse \
| while IFS=${ifs} read d s n e m t x; do
tag=$(grep -Po 'tag: [a-zA-Z]*\K[0-9a-f.]+' <<< "${x}"; :)
last_tag=${tag:-${last_tag:-0.0}}
dch_ver=${tag:-${last_tag}~git${d}.${s}}
if grep -q "(${dch_ver})" debian/changelog 2>/dev/null; then
continue
else
NAME=${n} EMAIL=${e} dch ${first---create --package ${PACKAGE}} ${first+-b} -v ${dch_ver} "${m//-/ }"
sed -i '1s/UNRELEASED/unstable/g;0,/\(> \).*/s//\1'"${t}"'/g' debian/changelog
first=''
[ -z "${VERSION}" ] || case "${dch_ver}" in
"${VERSION}")
echo "${dch_ver}${ifs}${d}${ifs}${s}"
break
;;
esac
fi
done)
[ -z "${ver_date_sha}" ] || for var_name in DCH_VER GIT_DATE SHORT_SHA; do
typeset -n v=${var_name}
v=${ver_date_sha%%${ifs}*}
ver_date_sha=${ver_date_sha#${v}${ifs}}
done
;;
esac
DCH_VER=${DCH_VER:-$(head -1 debian/changelog | grep -Po '(?:[a-z-]+\s)\(\K.*(?=\))')}
GIT_DATE=${GIT_DATE:-$(git log -1 --format=%ad --date=format:%Y%m%d)}
RELEASE_NAME=${PACKAGE}_${DCH_VER}
SHORT_SHA=${SHORT_SHA:-${GITHUB_SHA:0:7}}
TAG_NAME=${DCH_VER//\~/.}
for n in DCH_VER GIT_DATE RELEASE_NAME SHORT_SHA TAG_NAME; do
typeset -n v=${n}
echo "${n}=${v}"
done | tee -a $GITHUB_ENV
cat debian/changelog
[ ! -f debian/watch ] || sed -Ei 's|(https?://github.com/)\S+|\1'${GITHUB_REPOSITORY}'|g' debian/watch
dpkg-buildpackage -b -rfakeroot -us -uc
debs=$(grep -Poz '(?s)(?:\nPackage:\s*\K\N+|\nArchitecture:\K\s\N+\n)' debian/control \
| while read p a; do
case "${a}" in any) a=${DEB_BUILD_ARCH:-$(dpkg-architecture -q DEB_BUILD_ARCH)};; esac
deb=${p}_${DCH_VER}_${a}.deb
echo "p = ${p}; a = ${a}; deb = ${deb}" 1>&2
[ -f ../${deb} ] && mv ../${deb} . && echo ${BUILD_PATH:+${BUILD_PATH}/}${deb}
done)
[ -n "${debs}" ] && \
echo "DEBS<<EOL" >> $GITHUB_ENV && \
echo "${debs}" >> $GITHUB_ENV && \
echo EOL >> $GITHUB_ENV
shell: bash
- name: Export output variables
id: vars
shell: bash
run: |
[ -z ${{ env.debug }} ] || set -x
debs="${{ env.DEBS }}"
[ -n "${{ inputs.tag_name }}" ] && TAG_NAME="${{ inputs.tag_name }}" || TAG_NAME="${{ env.TAG_NAME }}"
[ -n "${{ inputs.release_name }}" ] && RELEASE_NAME="${{ inputs.release_name }}" || RELEASE_NAME="${{ env.RELEASE_NAME }}"
echo "files=${debs//$'\n'/%0A}" >> $GITHUB_OUTPUT
echo "release_name=${RELEASE_NAME}" >> $GITHUB_OUTPUT
echo "tag_name=${TAG_NAME}" >> $GITHUB_OUTPUT