-
Notifications
You must be signed in to change notification settings - Fork 0
44 lines (41 loc) · 1.53 KB
/
deploy.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
name: Deploy to production
on:
push:
branches:
- 'master'
paths:
- '.github/workflows/deploy.yml'
- 'version/**'
workflow_dispatch:
# we don't need GITHUB_TOKEN in this workflow
permissions: {}
jobs:
deploy:
name: Deploy to mirror
runs-on: self-hosted
environment: technic-mirror
steps:
- name: Pull changes
run: cd $MIRROR_BASEPATH && sudo -u $MIRROR_USER2 -H git pull
env:
MIRROR_BASEPATH: ${{ secrets.MIRROR_BASEPATH }}
MIRROR_USER2: ${{ secrets.MIRROR_USER2 }}
- name: Detect new MC versions
run: |
# abort on errors
set -euo pipefail
cd $MIRROR_BASEPATH
NEW_VERSION_PATHS="$(sudo -u $MIRROR_USER2 -H git diff --name-only --diff-filter=A "$GITHUB_REF_NAME@{1}".."$GITHUB_REF_NAME" -- version/)"
if [ -n "$NEW_VERSION_PATHS" ]; then
payload=$(printf '%s' "$NEW_VERSION_PATHS" | cut -d'/' -f2 | sort -V | \
jq --raw-input --slurp 'split("\n") | map(select(. != "")) | unique | join(", ") | "New MC versions: " + . | {content: .}')
printf 'Payload:\n%s\n' "$payload"
curl -X POST --fail-with-body --silent --show-error \
"${DISCORD_WEBHOOK_URL}?wait=true" \
-H 'Content-Type: application/json' \
-d "$payload"
fi
env:
MIRROR_BASEPATH: ${{ secrets.MIRROR_BASEPATH }}
MIRROR_USER2: ${{ secrets.MIRROR_USER2 }}
DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_WEBHOOK_URL }}