forked from raveberry/raveberry
-
Notifications
You must be signed in to change notification settings - Fork 0
187 lines (187 loc) · 7.38 KB
/
publish.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
name: Publish Raveberry
on:
push:
paths-ignore:
- 'docs/**'
- '**.md'
jobs:
build-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- uses: actions/setup-node@v2
with:
node-version: 'lts/*'
- run: pip install -r backend/requirements/frontend_build.txt
- run: yarn --cwd frontend install
- run: yarn --cwd frontend build
- uses: actions/upload-artifact@v2
with:
name: frontend-files
path: |
backend/static/bundle.js
backend/static/style.css
backend/static/*.woff2
test-frontend:
runs-on: ubuntu-latest
needs: build-frontend
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- uses: actions/setup-node@v2
with:
node-version: 'lts/*'
- uses: actions/download-artifact@v2
with:
name: frontend-files
path: backend/static/
- run: pip install -r backend/requirements/frontend_test.txt
- run: yarn --cwd frontend install
- run: yarn --cwd frontend test
test-backend:
runs-on: ubuntu-latest
services:
# from https://docs.github.com/en/actions/using-containerized-services/creating-postgresql-service-containers
postgres:
image: postgres
env:
POSTGRES_DB: raveberry
POSTGRES_USER: raveberry
POSTGRES_PASSWORD: raveberry
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
# from https://docs.github.com/en/actions/using-containerized-services/creating-redis-service-containers
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
# in order to use the raveberry/raveberry-mopidy container,
# we would need to share the songs cache. Instead, run mopidy on the host.
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install pip dependencies
run: pip install -r backend/requirements/backend_test.txt
- run: sudo apt-get update
- run: sudo apt-get -y install ffmpeg mopidy gstreamer1.0-plugins-bad
- name: Start mopidy
run: |
mopidy -o "audio/output=fakesink sync=true" &
# wait for mopidy so it can handle connections
sleep 5
- name: Prepare database
run: |
python backend/manage.py migrate
- run: python backend/manage.py test
test-install:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install pip dependencies
run: pip install -r backend/requirements/install.txt
- run: sudo apt-get update
- name: remove pyyaml
run: |
sudo rm -rf /usr/lib/python3/dist-packages/yaml
sudo rm -rf /usr/lib/python3/dist-packages/PyYAML-*
# https://stackoverflow.com/questions/73830524/attributeerror-module-lib-has-no-attribute-x509-v-flag-cb-issuer-check
- name: Fix preinstalled pip dependencies
run: pip install pyopenssl==19.0.0 cryptography==37.0.1
- run: sudo systemctl start postgresql
- run: bin/raveberry --confirm-config --use-default-password-i-promise-ill-change-it install
- name: Check if server is up
run: |
counter=0
until [[ $(curl -sS http://localhost/api/version/) == "Raveberry version"* ]] || [ $counter -gt 30 ]
do
counter=$((counter + 1))
sleep 1
done
# exit with failure if curl did not succeed in any iteration
[ $counter != 31 ]
check-versions:
runs-on: ubuntu-latest
outputs:
# use output instead of conclusion because there are issues if the step does not succeed
docker-status: ${{ steps.comparison.outputs.docker-status }}
pypi-status: ${{ steps.comparison.outputs.pypi-status }}
steps:
- uses: actions/checkout@v2
# https://docs.github.com/en/actions/learn-github-actions/workflow-commands-for-github-actions#setting-an-environment-variable
- run: echo "GITHUB_VERSION=$(cat backend/VERSION | tr -d '[:space:]')" >> $GITHUB_ENV
- run: echo "PYPI_VERSION=$(curl -Ls https://pypi.org/pypi/raveberry/json | jq -r .info.version | tr -d '[:space:]')" >> $GITHUB_ENV
- run: echo "DOCKER_VERSION=$(docker pull raveberry/raveberry >/dev/null && docker run raveberry/raveberry /bin/cat /opt/raveberry/VERSION | tr -d '[:space:]')" >> $GITHUB_ENV
- name: Compare versions
id: comparison
run: |
if [ "$DOCKER_VERSION" != "$GITHUB_VERSION" ]; then echo "::set-output name=docker-status::update"; fi
if [ "$PYPI_VERSION" != "$GITHUB_VERSION" ]; then echo "::set-output name=pypi-status::update"; fi
pypi-publish:
runs-on: ubuntu-latest
needs: [test-frontend, test-backend, test-install, check-versions]
if: needs.check-versions.outputs.pypi-status == 'update'
# from https://packaging.python.org/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: frontend-files
path: backend/static/
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- name: Install pypa/build
run: pip install build --user
- name: Rename module folder
run: ln -s backend raveberry
- name: Build a binary wheel and a source tarball
run: python -m build --sdist --wheel --outdir dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
docker-publish:
runs-on: ubuntu-latest
needs: [test-frontend, test-backend, test-install, check-versions]
if: needs.check-versions.outputs.docker-status == 'update'
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v2
with:
name: frontend-files
path: backend/static/
- run: echo "VERSION=$(cat backend/VERSION | tr -d '[:space:]')" >> $GITHUB_ENV
- uses: actions/setup-python@v2
with:
python-version: '3.9'
- uses: docker/login-action@v1
with:
username: raveberry
password: ${{ secrets.DOCKERHUB_TOKEN }}
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- run: pip install "django==4.*"
- name: Copy static admin files
run: cp -r "$(python -c 'import django, os; print(f"{os.path.dirname(django.__file__)}/contrib/admin/static/admin")')" backend/static/admin
- run: "docker buildx build --platform linux/amd64,linux/arm/v7 --output type=registry -f docker/Dockerfile -t raveberry/raveberry:$VERSION -t raveberry/raveberry ."
- run: "docker buildx build --platform linux/amd64,linux/arm/v7 --output type=registry -f docker/nginx.Dockerfile -t raveberry/raveberry-nginx:$VERSION -t raveberry/raveberry-nginx ."