forked from scop/bash-completion
-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (140 loc) · 5.18 KB
/
ci.yaml
File metadata and controls
150 lines (140 loc) · 5.18 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
name: ci
on:
pull_request:
push:
branches:
- master
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ">=3.6"
- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: pip-${{hashFiles('test/requirements*.txt')}}
- uses: actions/cache@v3
with:
path: ~/.cache/pre-commit
key: pre-commit-${{hashFiles('.pre-commit-config.yaml')}}
- name: Install dependencies
run: |
python3 -m venv venv # for venv-run
source venv/bin/activate
python3 -m pip install -Ur test/requirements-dev.txt
- name: Run checks
run: |
source venv/bin/activate
# Commit message checks
tmpdir=$(mktemp -d)
trap "rm -r '$tmpdir'" EXIT
commits_json=$tmpdir/commits.json
commit_txt=$tmpdir/message.txt
# For push, commits are available directly in github.event.commits.
# For pull_request they're not: grab them from API, transform fields
# we want to a similar structure as pushes are.
if [[ "${{github.event.commits}}" ]]; then
cat <<\EOF >"$commits_json"
${{toJSON(github.event.commits)}}
EOF
else
curl -fSsL ${{github.event.pull_request.commits_url}} | \
jq '[.[] | {id: .sha, message: .commit.message}]' >"$commits_json"
fi
git config user.name $(git log -1 --format=format:%an)
git config user.email $(git log -1 --format=format:%ae)
rc=0
for id in $(jq --raw-output '.[].id' <"$commits_json"); do
jq --raw-output ".[] | select(.id==\"$id\") | .message" \
<"$commits_json" >"$commit_txt"
echo "Linting commit $id message..."
set +e
pre-commit run gitlint \
--color=always \
--hook-stage=commit-msg \
--commit-msg-filename="$commit_txt"
((rc+=$?))
set -e
done
# Other pre-commit checks
set +e
pre-commit run --color=always --all-files --show-diff-on-failure
((rc+=$?))
set -e
exit $rc
distcheck:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- dist: alpine
- dist: centos7
- dist: debian10
- dist: debian10
bsd: true
network: none
- dist: fedoradev
- dist: ubuntu14
steps:
- uses: actions/checkout@v3
- uses: GoogleCloudPlatform/release-please-action@v3
with:
release-type: simple
pull-request-title-pattern: "chore: release${component} ${version}"
id: release
if: github.event_name == 'push' && matrix.dist == 'alpine'
- name: Do release preparations
run: |
version=$(cat version.txt)
sed -i -re "s/^(BASH_COMPLETION_VERSINFO=).*/\\1(${version//./ })/" bash_completion
sed -i -re "s/^(AC_INIT\(.*\[)[0-9.]+(\].*)/\\1$version\\2/" configure.ac
git config user.name $(git log -1 --format=format:%an)
git config user.email $(git log -1 --format=format:%ae)
git commit --message="chore: bump release in dist files" bash_completion configure.ac
git tag --force ${{steps.release.outputs.tag_name}}
git push
git push --tags --force
if: steps.release.outputs.release_created
# A "container" workflow config would be cleaner here, but comes with
# some restrictions/oddities: changes root's $HOME to /github/home
# without changing the actual home dir that can cause some problems,
# and does not provide a way to run with --network none.
# fedoradev unconfined: https://bugzilla.redhat.com/1900021
- name: Run main build
run: >-
docker run
--rm
--tty
--env CI=true
--env DIST=${{matrix.dist}}
--env BSD=${{matrix.bsd}}
--env PYTESTFLAGS=--verbose
--env NETWORK=$NETWORK
${NETWORK:+--network $NETWORK}
$(test $DIST = fedoradev && echo --security-opt seccomp=unconfined)
--volume $PWD:/usr/src/bash-completion
--workdir /usr/src/bash-completion
ghcr.io/scop/bash-completion/test:${{matrix.dist}}
test/docker/entrypoint.sh
env:
DIST: ${{matrix.dist}}
NETWORK: ${{matrix.network}}
- name: Upload release assets
run: |
set -x
upload_url="${{steps.release.outputs.upload_url}}"
tarball="bash-completion-$(cat version.txt).tar.xz"
curl \
--header "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" \
--header "Accept: application/vnd.github.v3+json" \
--header "Content-Type: application/x-xz-compressed-tar" \
--data-binary "@$tarball" \
"${upload_url%{*}?name=$tarball"
if: steps.release.outputs.release_created
- uses: actions/upload-artifact@v2
with:
path: bash-completion-*.tar.xz
if: matrix.dist == 'alpine'