aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows
diff options
context:
space:
mode:
authorMoulberry <jjenour@student.unimelb.edu.au>2022-03-03 11:03:58 +0800
committerGitHub <noreply@github.com>2022-03-03 11:03:58 +0800
commit7c6d37b2eb758a13b342b906f0aef88b940bc52a (patch)
tree9602a014425b859e3aba98f31f93d6de04521356 /.github/workflows
parentb11742988dec635b5c5da7c2363803cbfafb37b1 (diff)
parentdb59eba3fd9121c7c0a88363994876c5b582c08c (diff)
downloadNotEnoughUpdates-7c6d37b2eb758a13b342b906f0aef88b940bc52a.tar.gz
NotEnoughUpdates-7c6d37b2eb758a13b342b906f0aef88b940bc52a.tar.bz2
NotEnoughUpdates-7c6d37b2eb758a13b342b906f0aef88b940bc52a.zip
Merge pull request #248 from NotEnoughUpdates/master
NEU 2.1 🙂
Diffstat (limited to '.github/workflows')
-rw-r--r--.github/workflows/build.yml55
-rwxr-xr-x.github/workflows/send_webhook_update.sh88
2 files changed, 125 insertions, 18 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 2df530bf..3b6d0cbd 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -2,13 +2,15 @@ name: Build
on:
push:
- branches: [ master ]
+ branches:
+ - '*'
paths-ignore:
- 'README.md'
- 'LICENSE'
- '.gitignore'
pull_request:
- branches: [ master ]
+ branches:
+ - '*'
paths-ignore:
- 'README.md'
- 'LICENSE'
@@ -16,27 +18,44 @@ on:
workflow_dispatch:
jobs:
build:
-
+ env:
+ GIT_URL: ${{ github.server_url }}/${{ github.repository }}/tree/${{ github.sha }}
+ REF_NAME: ${{ github.ref_name }}
+ WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}
+ ACTOR: ${{ github.actor }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- - name: Set up JDK 1.8
- uses: actions/setup-java@v1
- with:
- java-version: 1.8
- - uses: actions/cache@v2
+ - name: Send discord notification
+ id: sendmsg
+ if: ${{ env.WEBHOOK_URL }}
+ run: |
+ ./.github/workflows/send_webhook_update.sh
+ env:
+ STATUS: WORKING
+ - name: Set up JDK 8
+ uses: actions/setup-java@v2
with:
- path: |
- ~/.gradle/caches
- ~/.gradle/wrapper
- key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
- restore-keys: |
- ${{ runner.os }}-gradle-
- - name: Grant execute permission for gradlew
- run: chmod +x gradlew
+ java-version: 8
+ distribution: zulu
+ cache: gradle
- name: Build with Gradle
- run: ./gradlew build --no-daemon
+ run: chmod +x ./gradlew && ./gradlew setupCIWorkspace build --no-daemon
- uses: actions/upload-artifact@v2
with:
- path: build/libs/*.jar
+ path: build/libs/*-dep.jar
+ - name: Update discord notification
+ if: ${{ env.WEBHOOK_URL && success() }}
+ run: |
+ ./.github/workflows/send_webhook_update.sh
+ env:
+ STATUS: SUCCESS
+ MESSAGE_ID: ${{ steps.sendmsg.outputs.MESSAGE_ID }}
+ - name: Update discord notification
+ if: ${{ env.WEBHOOK_URL && failure() }}
+ run: |
+ ./.github/workflows/send_webhook_update.sh
+ env:
+ STATUS: FAILURE
+ MESSAGE_ID: ${{ steps.sendmsg.outputs.MESSAGE_ID }}
diff --git a/.github/workflows/send_webhook_update.sh b/.github/workflows/send_webhook_update.sh
new file mode 100755
index 00000000..56852159
--- /dev/null
+++ b/.github/workflows/send_webhook_update.sh
@@ -0,0 +1,88 @@
+#!/bin/bash
+set -x
+
+COLOR_SUCCESS=8040199
+COLOR_WORKING=7472302
+COLOR_ERROR=14960972
+case "$STATUS" in
+ WORKING)
+ color="$COLOR_WORKING"
+ status_message="Build started."
+ ;;
+ FAILURE)
+ color="$COLOR_ERROR"
+ status_message="Build failed."
+ ;;
+ SUCCESS)
+ color="$COLOR_SUCCESS"
+ status_message="Build succeeded."
+ to_upload=$(echo build/libs/*-dep.jar)
+ upload_name=NotEnoughUpdates-beta-dep.jar
+ ;;
+esac
+
+author_name="$ACTOR"
+commit_hash=$(git log -1 --pretty=format:'%h')
+commit_subject=$(git log -1 --pretty=format:'%s')
+commit_body=$(git log -1 --pretty=format:'%b')
+commit_date=$(git log -1 --pretty=format:'%ct')
+
+author_avatar="https://github.com/$author_name.png"
+
+#language=json
+read -r -d '' structure <<-"EOF"
+{
+ "content": $status,
+ "username": $username,
+ "avatar_url": $avatar_url,
+ "embeds": [
+ {
+ "color": $color,
+ "url": $url,
+ "title": $subject,
+ "description": $body,
+ "footer": {
+ "text": $ref
+ }
+ }
+ ],
+ "allowed_mentions": {
+ "parse": []
+ }
+}
+EOF
+json=$(jq -n \
+ --arg body "$commit_body" \
+ --arg status "$status_message" \
+ --arg subject "$commit_subject" \
+ --arg username "$author_name" \
+ --arg avatar_url "$author_avatar" \
+ --argjson color "$color" \
+ --arg url "$GIT_URL" \
+ --arg ref "$REF_NAME" \
+ "$structure")
+
+function make_request() {
+ if [ "$to_upload" != "" ]; then
+ upload_arg="-F"
+ fi
+ curl -X $1 -H "Content-Type: multipart/form-data" -F "payload_json=$json" "$upload_arg" "$upload_name=@$to_upload" "$WEBHOOK_URL$2?wait=true"
+}
+
+echo "Should replace message with id: $MESSAGE_ID"
+if [ "$MESSAGE_ID" != "" ]; then
+ discord_output=$(make_request PATCH "/messages/$MESSAGE_ID")
+ RESULT=$?
+else
+ discord_output=$(make_request POST)
+ RESULT=$?
+fi
+
+if [ $RESULT != 0 ]; then
+ echo "$discord_output"
+ exit 1
+fi
+echo "Message sent to discord."
+echo "$discord_output" | jq .
+id_string=$(echo "$discord_output" | jq .id)
+echo "::set-output name=MESSAGE_ID::${id_string//\"/}"