187 lines
6.5 KiB
YAML
187 lines
6.5 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- '**'
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
test:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 18
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Lint
|
|
run: npm run lint
|
|
|
|
- name: Test
|
|
run: npm test
|
|
|
|
- name: Notify success (ntfy)
|
|
if: success()
|
|
run: |
|
|
curl -fsS \
|
|
-H "Title: Iris CI success" \
|
|
-H "Priority: low" \
|
|
-H "Tags: success,iris" \
|
|
-H "Actions: view, Changes, ${{ gitea.server_url }}/${{ gitea.repository }}/commit/${{ gitea.sha }}; view, Build, ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
|
-d "✅ Build succeeded: ${{ gitea.repository }} @ ${{ gitea.sha }}" \
|
|
https://ntfy.unbl.ink/drone
|
|
|
|
- name: Notify failure (ntfy)
|
|
if: failure()
|
|
run: |
|
|
curl -fsS \
|
|
-H "Title: Iris CI failure" \
|
|
-H "Priority: high" \
|
|
-H "Tags: failure,iris" \
|
|
-H "Actions: view, Changes, ${{ gitea.server_url }}/${{ gitea.repository }}/commit/${{ gitea.sha }}; view, Build, ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
|
-d "❌ Build failed: ${{ gitea.repository }} @ ${{ gitea.sha }}" \
|
|
https://ntfy.unbl.ink/drone
|
|
|
|
deploy:
|
|
if: github.ref == 'refs/heads/main' && needs.test.result == 'success'
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 18
|
|
|
|
- name: Get version
|
|
id: version
|
|
run: echo "version=$(cat IRIS_VERSION)" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build frontend assets
|
|
run: |
|
|
npm ci
|
|
npm run prod
|
|
|
|
- name: Build Python sdist
|
|
run: |
|
|
pip install --break-system-packages build
|
|
python -m build --sdist
|
|
|
|
- name: Upload sdist to Gitea release
|
|
continue-on-error: true
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA }}
|
|
run: |
|
|
set -x
|
|
VERSION=$(cat IRIS_VERSION)
|
|
echo "Version: ${VERSION}"
|
|
|
|
ASSET=$(ls dist/Mopidy_*.tar.gz dist/Mopidy-*.tar.gz 2>/dev/null | head -1)
|
|
echo "Asset: ${ASSET}"
|
|
if [ -z "$ASSET" ]; then
|
|
echo "ERROR: no sdist tarball found in dist/"
|
|
ls -la dist/ 2>/dev/null || echo "dist/ does not exist"
|
|
exit 1
|
|
fi
|
|
if [ ! -f "$ASSET" ]; then
|
|
echo "ERROR: asset file missing: ${ASSET}"
|
|
exit 1
|
|
fi
|
|
|
|
AUTH="Authorization: token ${GITEA_TOKEN}"
|
|
API="http://gitea.service:3000/api/v1/repos/secstate/Iris"
|
|
|
|
# Delete old release first (by tag lookup), then delete the tag
|
|
echo "--- Looking up existing release ---"
|
|
OLD_ID=$(curl -sf "${API}/releases/tags/continuous" \
|
|
-H "${AUTH}" \
|
|
| python3 -c "import sys,json;print(json.load(sys.stdin).get('id',''))" 2>/dev/null || echo "")
|
|
if [ -n "$OLD_ID" ]; then
|
|
echo "Deleting old release ID=${OLD_ID}"
|
|
curl -f -X DELETE "${API}/releases/${OLD_ID}" -H "${AUTH}" \
|
|
-w "\nDELETE release HTTP %{http_code}\n" || echo "Delete release returned non-zero"
|
|
else
|
|
echo "No existing release found"
|
|
fi
|
|
|
|
echo "--- Deleting old tag ---"
|
|
curl -f -X DELETE "${API}/tags/continuous" -H "${AUTH}" \
|
|
-w "DELETE tag HTTP %{http_code}\n" || echo "Tag delete non-zero (may not exist)"
|
|
|
|
echo "--- Creating release ---"
|
|
RELEASE_ID=$(curl -f -X POST "${API}/releases" \
|
|
-H "${AUTH}" \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"tag_name":"continuous","name":"Continuous build","prerelease":true,"target_commitish":"main"}' \
|
|
-w "\nCREATE release HTTP %{http_code}\n" \
|
|
| tee /dev/stderr \
|
|
| python3 -c "import sys,json;print(json.load(sys.stdin)['id'])" 2>/dev/null) || {
|
|
echo "ERROR: failed to create release"
|
|
exit 1
|
|
}
|
|
echo "Created release ID=${RELEASE_ID}"
|
|
|
|
echo "--- Uploading asset ---"
|
|
curl -f -X POST "${API}/releases/${RELEASE_ID}/assets" \
|
|
-H "${AUTH}" \
|
|
-F "attachment=@${ASSET}" \
|
|
-w "\nUPLOAD asset HTTP %{http_code}\n" || {
|
|
echo "ERROR: asset upload failed"
|
|
exit 1
|
|
}
|
|
echo "--- Done ---"
|
|
|
|
- name: Copy sdist to server
|
|
uses: appleboy/scp-action@v0.1.7
|
|
with:
|
|
host: mopidy-dev.service
|
|
username: root
|
|
key: ${{ secrets.JAIL_KEY }}
|
|
target: /tmp/iris-deploy/
|
|
source: dist/
|
|
|
|
- name: Install on server
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: mopidy-dev.service
|
|
username: root
|
|
key: ${{ secrets.JAIL_KEY }}
|
|
script: |
|
|
pip uninstall -y --break-system-packages mopidy-iris
|
|
pip install --break-system-packages /tmp/iris-deploy/dist/*.tar.gz
|
|
rm -rf /tmp/iris-deploy
|
|
service mopidy restart
|
|
|
|
- name: Notify deploy success (ntfy)
|
|
if: success()
|
|
run: |
|
|
curl -fsS \
|
|
-H "Title: Iris deploy success" \
|
|
-H "Priority: low" \
|
|
-H "Tags: success,iris,deploy" \
|
|
-H "Actions: view, View changes, ${{ gitea.server_url }}/${{ gitea.repository }}/commit/${{ gitea.sha }}; view, View build, ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
|
-d "🚀 Deploy succeeded: ${{ gitea.ref_name }} (${{ gitea.sha }})" \
|
|
https://ntfy.unbl.ink/drone
|
|
|
|
- name: Notify deploy failure (ntfy)
|
|
if: failure()
|
|
run: |
|
|
curl -fsS \
|
|
-H "Title: Iris deploy failure" \
|
|
-H "Priority: high" \
|
|
-H "Tags: failure,iris,deploy" \
|
|
-H "Actions: view, View changes, ${{ gitea.server_url }}/${{ gitea.repository }}/commit/${{ gitea.sha }}; view, View build, ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" \
|
|
-d "💥 Deploy failed: ${{ gitea.ref_name }} (${{ gitea.sha }})" \
|
|
https://ntfy.unbl.ink/drone
|