Skip to content

Commit

Permalink
Merge pull request #101 from peach-bot/develop
Browse files Browse the repository at this point in the history
CI Tweaks, Spotify fixes
  • Loading branch information
julxyz authored Jun 21, 2021
2 parents bffd599 + 80c5041 commit 8fb8a32
Show file tree
Hide file tree
Showing 41 changed files with 746 additions and 571 deletions.
18 changes: 7 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
.vscode
notes
secrets
devsecrets
vendor
*.exe
build
scripts/hash
*.pem

**/vendor
node_modules
launchcfg.json
scripts/getguildsettings.sql

scripts/getusersettings.sql
build
scripts/hash

TODO
launchcfg.json
TODO
12 changes: 4 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ go:
jobs:
include:
- stage: Test
script:
- go get golang.org/x/tools/cmd/stringer
- go mod download
- go generate ./...
script:
- ./scripts/test.sh
- ./scripts/build.sh
- stage: Deploy
script:
- go get golang.org/x/tools/cmd/stringer
- go mod download
- go generate ./...
if: branch = master
script:
- ./scripts/build.sh
deploy:
provider: releases
Expand Down
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at floofyjul@gmail.com. All
reported by contacting the project team at jul@jul.xyz. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
A Discord server management and chat bot with loads of handy features<br><br>
<a href="https://github.com/peach-bot/Peach/releases"><img src="https://img.shields.io/github/v/release/peach-bot/peach?color=brightgreen&include_prereleases&style=flat-square" alt="GitHub version"></img></a>
<a href="https://travis-ci.com/peach-bot/Peach/branches"><img src="https://img.shields.io/travis/com/peach-bot/Peach/master?style=flat-square" alt="Build Status"></img></a>
<a href="https://goreportcard.com/report/github.com/peach-bot/Peach"><img src="https://img.shields.io/badge/go%20report-A+-brightgreen.svg?style=flat-square" alt="Go Report"></img></a>
<a href="https://github.com/peach-bot/Peach/blob/master/LICENSE"><img src="https://img.shields.io/github/license/peach-bot/Peach?color=brightgreen&style=flat-square" alt="License"></img></a>
<a href="#contributors"><img src="https://img.shields.io/github/contributors/peach-bot/Peach?style=flat-square" alt="Contributors"></img></a>
<a href="https://github.com/peach-bot/Peach/issues"><img src="https://img.shields.io/github/issues-raw/peach-bot/peach?style=flat-square" alt="Open Issues"></img></a><br><br>
Expand Down
12 changes: 9 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ go 1.13

require (
github.com/alessio/shellescape v1.4.1
github.com/golang/protobuf v1.5.2 // indirect
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.4.2
github.com/hako/durafmt v0.0.0-20210316092057-3a2c319c1acd
github.com/jackc/pgproto3/v2 v2.0.7 // indirect
github.com/jackc/pgx/v4 v4.11.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/stretchr/testify v1.7.0
github.com/zmb3/spotify v1.1.2
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/text v0.3.5
gopkg.in/alessio/shellescape.v1 v1.0.0-20170105083845-52074bc9df61
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect
golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6 // indirect
golang.org/x/oauth2 v0.0.0-20210413134643-5e61552d6c78
golang.org/x/sys v0.0.0-20210426230700-d19ff857e887 // indirect
golang.org/x/text v0.3.6
google.golang.org/appengine v1.6.7 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
)
290 changes: 286 additions & 4 deletions go.sum

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions launchcfg.json.template
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"clients": {
"sharded": true,
"shards": 2,
"token": "",
"launcher": {
"max_clients": 5,
"log_level": "info",
"coordinator": "http://localhost:8080/api/",
"spotify_client_id": "2ih14ihojk21hjko312kjh",
"spotify_client_secret": "3iuhj4i2huuih4oj32uhio423"
"coordinator": "http://localhost:8080/api/"
},
"clientcoordinator": {
"launch": true,
"port": "5000",
"dbc": "database, user, password, host, port",
"spotify_client_id": "2ih14ihojk21hjko312kjh",
"spotify_client_secret": "3iuhj4i2huuih4oj32uhio423",
"cert_type": "letsencrypt",
"domain": "example.domain"
},
Expand Down
61 changes: 32 additions & 29 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,28 @@ build () {
then
sudo systemctl stop peach
fi

printf "Building project\n"

# make directories for build and hash files
mkdir -p build || fail
mkdir -p scripts/hash || fail
if [[ $args == *"f"* ]]
then
rm -r scripts/hash || fail
mkdir -p scripts/hash || fail
fi

printf "Copying files..."
cp launchcfg.json build/launchcfg.json

# generate service files
echo "s/\${version}/$version/" > ./scripts/replace.txt
sed -f ./scripts/replace.txt ./scripts/launcher_service_template.txt > build/peach_launcher.service
sed -f ./scripts/replace.txt ./scripts/coordinator_service_template.txt > build/peach_coordinator.service
rm ./scripts/replace.txt


printf "done\n"

printf "Collecting dependencies..."
Expand All @@ -25,7 +42,7 @@ build () {
then
waittillstopped
cp build/. /home/peach -r || fail
cp peach.service /etc/systemd/system/peach.service
cp build/peach.service /etc/systemd/system/peach.service
sudo systemctl daemon-reload
fi
if [[ $args == *"r"* ]]
Expand All @@ -35,7 +52,6 @@ build () {
}

hash () {
mkdir -p scripts/hash || fail
newhash=$(find ./src/$1 -type f -print0 | xargs -0 sha1sum)
echo $newhash > scripts/hash/$1_new.hash
newhash=$(<scripts/hash/$1_new.hash)
Expand Down Expand Up @@ -76,20 +92,20 @@ waittillstopped() {
}

buildcoordinator() {
printf "Building client coordinator"
printf "Building coordinator"

#check hash
hash "peach_client_coordinator"
hash "peach_coordinator"
h=$?
if [[ "$h" == "1" ]]; then
printf "\nSkipping. No changes were made.\n"
return
fi

printf "\nCompiling..."
go build -o build/coordinator-$version.exe ./src/peach_client_coordinator || fail
printf "\nDone building client coordinator\n"
storehash "peach_client_coordinator"
go build -o build/coordinator-$version.exe ./src/peach_coordinator || fail
printf "\nDone building coordinator\n"
storehash "peach_coordinator"
}

builddiscordclient() {
Expand All @@ -105,10 +121,10 @@ builddiscordclient() {

printf "\nCompiling..."

printf "package main\n
// VERSION represents the release the bot is currently running on.
// This file is automatically generated by the build script. Do not edit.
const VERSION = \"$version\"" > src/peach_discord_client/version.go
echo "s/\${version}/$version/" > ./scripts/replace.txt
sed -f ./scripts/replace.txt ./scripts/version_template.txt > src/peach_discord_client/version.go
rm ./scripts/replace.txt

go build -o build/discordclient-$version.exe ./src/peach_discord_client || fail
printf "\nDone building discord client\n"
storehash "peach_discord_client"
Expand All @@ -127,10 +143,9 @@ buildlauncher() {

printf "\nCompiling..."

printf "package main\n
// VERSION represents the release the bot is currently running on.
// This file is automatically generated by the build script. Do not edit.
const VERSION = \"$version\"" > src/peach_launcher/version.go
echo "s/\${version}/$version/" > ./scripts/replace.txt
sed -f ./scripts/replace.txt ./scripts/version_template.txt > src/peach_launcher/version.go
rm ./scripts/replace.txt

go build -o build/launcher-$version.exe ./src/peach_launcher || fail
printf "\nDone building launcher\n"
Expand All @@ -147,23 +162,11 @@ if [[ $args == "-"* ]]
then
if [[ $args == *"h"* ]]
then
printf "Builds the project\nUsage: ./build.sh [OPTIONS]\n\nOptions:\n -h prints this page\n -i installs built project\n -d installs dependencies\n -r restarts the system service\n"
printf "Builds the project\nUsage: ./build.sh [OPTIONS]\n\nOptions:\n -h prints this page\n -f ignore cache and build all modules\n -i installs built project\n -d installs dependencies\n -r restarts the system service\n"
exit
fi
fi

version=$(git describe --tags)
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$branch" == "master" ]]; then
branch=""
else
branch="-$branch"
fi
version=${version%-*-*}
version="$version$branch"

if [[ "$TRAVIS_TAG" != "" ]]; then
version="$TRAVIS_TAG"
fi
version=$(./scripts/version.sh)

build
13 changes: 13 additions & 0 deletions scripts/coordinator_service_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=Peach Discord Bot
After=network.target

[Service]
Type=simple
User=peach
ExecStart=/home/peach/coordinator-${version}.exe
Restart=always
WorkingDirectory=/home/peach

[Install]
WantedBy=default.target
2 changes: 0 additions & 2 deletions scripts/createsecrets.sh

This file was deleted.

11 changes: 0 additions & 11 deletions scripts/deploy.sh

This file was deleted.

1 change: 0 additions & 1 deletion scripts/generate.sh

This file was deleted.

2 changes: 1 addition & 1 deletion peach.service → scripts/launcher_service_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ After=network.target
[Service]
Type=simple
User=peach
ExecStart=/home/peach/launcher.exe
ExecStart=/home/peach/launcher-${version}.exe
Restart=always
WorkingDirectory=/home/peach

Expand Down
12 changes: 2 additions & 10 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ function on_exit()
trap "on_exit" 2
echo "Running launcher"

version=$(git describe --tags)
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$branch" == "master" ]]; then
branch=""
else
branch="-$branch"
fi
version=${version%-*-*}
version="$version$branch"
version=$(./scripts/version.sh)

cd build
./launcher-$version.exe
./launcher-$version.exe & ./coordinator-$version.exe && fg
4 changes: 3 additions & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
go test -v ./src/...
go test -v ./src/peach_discord_client
go test -v ./src/peach_coordinator
go test -v ./src/peach_launcher
15 changes: 15 additions & 0 deletions scripts/version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if [[ "$TRAVIS_TAG" != "" ]]; then
version="$TRAVIS_TAG"
else
version=$(git describe --tags)
branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$branch" == "master" ]]; then
branch=""
else
branch="-$branch"
fi
version=${version%-*-*}
version="$version$branch"
fi

echo $version
5 changes: 5 additions & 0 deletions scripts/version_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

// VERSION represents the release the bot is currently running on.
// This file is automatically generated by the build script. Do not edit.
const VERSION = "${version}"
Loading

0 comments on commit 8fb8a32

Please sign in to comment.