Skip to content

Commit ad9f114

Browse files
authored
Merge pull request #436 from FiendsOfTheElements/deploy_prs
TEST: deploy PRs
2 parents ea682f6 + fd6398a commit ad9f114

13 files changed

Lines changed: 200 additions & 88 deletions

File tree

.circleci/build.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
set -o errexit
3+
set -x
4+
5+
sed -i "s/SHA/${CIRCLE_SHA1}/" FF1Lib/FFRVersion.cs
6+
sed -i "s|BRANCH|${CIRCLE_BRANCH}|" FF1Lib/FFRVersion.cs
7+
8+
cd FF1Blazorizer
9+
10+
config=$(jq -r ".branchConfig | map(select(if .branch == \"default\" then true elif .branch == \"${CIRCLE_BRANCH}\" then true else false end)) | .[0]" ../.circleci/configs/config.json)
11+
echo "$config" | cat
12+
longName=$(echo "$config" | jq -r ".longName")
13+
shortName=$(echo "$config" | jq -r ".shortName")
14+
cssFile=$(echo "$config" | jq -r ".cssFile")
15+
themeColor=$(echo "$config" | jq -r ".themeColor")
16+
siteIcon=$(echo "$config" | jq -r ".siteIcon")
17+
releaseBuild=$(echo "$config" | jq -r ".releaseBuild")
18+
19+
sed -i "s/NAME_LONG/${longName}/g" wwwroot/manifest.published.json
20+
sed -i "s/NAME_SHORT/$shortName/g" wwwroot/manifest.published.json
21+
sed -i "s/DARK_BACKGROUND_COLOR/$themeColor/g" wwwroot/manifest.published.json
22+
sed -i "s/DARK_BACKGROUND_COLOR/$themeColor/g" wwwroot/index.html
23+
sed -i "s/main.css/$cssFile/g" wwwroot/css/site.css
24+
sed -i "s/SITE_ICON_COLOR/$siteIcon/g" wwwroot/manifest.published.json
25+
sed -i "s/SITE_ICON_COLOR/$siteIcon/g" wwwroot/index.html
26+
mv -f wwwroot/manifest.published.json wwwroot/manifest.json
27+
if "$releaseBuild"; then
28+
dotnet publish -c Release -o output
29+
else
30+
dotnet publish -c Debug -o output
31+
fi

.circleci/config.yml

Lines changed: 16 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
version: 2.1
2+
13
defaults: &defaults
4+
25
working_directory: ~/ff1randomizer
36
docker:
47
- image: fiendsoftheelements/netlify-build:alpine
58

6-
version: 2
9+
orbs:
10+
shellcheck: circleci/shellcheck@1.3.16
11+
712
jobs:
813
build:
914
working_directory: ~/ff1randomizer
@@ -13,49 +18,7 @@ jobs:
1318
- checkout
1419
- run:
1520
name: publish
16-
command: |
17-
set -ex
18-
19-
sed -i "s/SHA/${CIRCLE_SHA1}/" FF1Lib/FFRVersion.cs
20-
sed -i "s/BRANCH/${CIRCLE_BRANCH}/" FF1Lib/FFRVersion.cs
21-
22-
cd FF1Blazorizer
23-
24-
if [ "${CIRCLE_BRANCH}" == "master" ]; then
25-
sed -i 's/NAME_LONG/FFRandomizer/g' wwwroot/manifest.published.json
26-
sed -i 's/NAME_SHORT/FFR/g' wwwroot/manifest.published.json
27-
color=$(grep "DARK_BACKGROUND_COLOR: #.*" wwwroot/css/main.css | grep -o "#[0-9a-fA-F]*")
28-
sed -i "s/DARK_BACKGROUND_COLOR/$color/g" wwwroot/manifest.published.json
29-
sed -i "s/DARK_BACKGROUND_COLOR/$color/g" wwwroot/index.html
30-
sed -i 's/SITE_ICON_COLOR/normal/g' wwwroot/manifest.published.json
31-
sed -i 's/SITE_ICON_COLOR/normal/g' wwwroot/index.html
32-
mv -f wwwroot/manifest.published.json wwwroot/manifest.json
33-
dotnet publish -c Release -o output
34-
elif [ "${CIRCLE_BRANCH}" == "dev" ]; then
35-
sed -i 's/NAME_LONG/FFRandomizer - beta/g' wwwroot/manifest.published.json
36-
sed -i 's/NAME_SHORT/FFR β/g' wwwroot/manifest.published.json
37-
color=$(grep "DARK_BACKGROUND_COLOR: #.*" wwwroot/css/beta.css | grep -o "#[0-9a-fA-F]*")
38-
sed -i "s/DARK_BACKGROUND_COLOR/$color/g" wwwroot/manifest.published.json
39-
sed -i "s/DARK_BACKGROUND_COLOR/$color/g" wwwroot/index.html
40-
sed -i 's/main.css/beta.css/g' wwwroot/css/site.css
41-
sed -i 's/SITE_ICON_COLOR/cyan/g' wwwroot/manifest.published.json
42-
sed -i 's/SITE_ICON_COLOR/cyan/g' wwwroot/index.html
43-
mv -f wwwroot/manifest.published.json wwwroot/manifest.json
44-
dotnet publish -c Debug -o output
45-
elif [ "${CIRCLE_BRANCH}" == "alpha" ]; then
46-
sed -i 's/NAME_LONG/FFRandomizer - alpha/g' wwwroot/manifest.published.json
47-
sed -i 's/NAME_SHORT/FFR α/g' wwwroot/manifest.published.json
48-
color=$(grep "DARK_BACKGROUND_COLOR: #.*" wwwroot/css/alpha.css | grep -o "#[0-9a-fA-F]*")
49-
sed -i "s/DARK_BACKGROUND_COLOR/$color/g" wwwroot/manifest.published.json
50-
sed -i "s/DARK_BACKGROUND_COLOR/$color/g" wwwroot/index.html
51-
sed -i 's/main.css/alpha.css/g' wwwroot/css/site.css
52-
sed -i 's/SITE_ICON_COLOR/red/g' wwwroot/manifest.published.json
53-
sed -i 's/SITE_ICON_COLOR/red/g' wwwroot/index.html
54-
mv -f wwwroot/manifest.published.json wwwroot/manifest.json
55-
dotnet publish -c Debug -o output
56-
else
57-
dotnet publish -c Debug -o output
58-
fi
21+
command: sh .circleci/build.sh
5922
- persist_to_workspace:
6023
root: ~/ff1randomizer/FF1Blazorizer/output
6124
paths:
@@ -69,28 +32,19 @@ jobs:
6932
at: ~/ff1randomizer/FF1Blazorizer/output
7033
- run:
7134
name: deploy
72-
command: |
73-
if [ "${CIRCLE_BRANCH}" == "master" ]; then
74-
netlify deploy --dir=/root/ff1randomizer/FF1Blazorizer/output/wwwroot --prod --site=cd1fef70-df7f-44ab-b1c8-3239dae773ac
75-
elif [ "${CIRCLE_BRANCH}" == "dev" ]; then
76-
netlify deploy --dir=/root/ff1randomizer/FF1Blazorizer/output/wwwroot --prod --site=b1e4219e-dfb6-4efa-924f-3136bbf3fa26
77-
else
78-
netlify deploy --dir=/root/ff1randomizer/FF1Blazorizer/output/wwwroot --prod --site=61141991-cfa6-4a2e-ab6b-187b1611a2e4
79-
fi
80-
81-
35+
command: sh .circleci/deploy.sh
8236

8337
workflows:
84-
version: 2
8538
main:
8639
jobs:
87-
- build
40+
- shellcheck/check:
41+
path: ".circleci/"
42+
- build:
43+
requires:
44+
- shellcheck/check
45+
- hold:
46+
type: approval
8847
- deploy:
8948
requires:
49+
- hold
9050
- build
91-
filters:
92-
branches:
93-
only:
94-
- master
95-
- dev
96-
- alpha

.circleci/configs/config.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "./configSchema.json",
3+
"branchConfig": [
4+
{
5+
"branch": "master",
6+
"longName": "FFRandomizer",
7+
"shortName": "FFR",
8+
"themeColor": "#221d11",
9+
"cssFile": "main.css",
10+
"siteIcon": "normal",
11+
"releaseBuild": true,
12+
"netlifyID": "cd1fef70-df7f-44ab-b1c8-3239dae773ac",
13+
"deployPreview": false
14+
},
15+
{
16+
"branch": "dev",
17+
"longName": "FFRandomizer - beta",
18+
"shortName": "FFR β",
19+
"themeColor": "#111122",
20+
"cssFile": "beta.css",
21+
"siteIcon": "cyan",
22+
"releaseBuild": false,
23+
"netlifyID": "b1e4219e-dfb6-4efa-924f-3136bbf3fa26",
24+
"deployPreview": false
25+
},
26+
{
27+
"branch": "default",
28+
"longName": "FFRandomizer - PR",
29+
"shortName": "FFR PR",
30+
"themeColor": "#221119",
31+
"cssFile": "alpha.css",
32+
"siteIcon": "red",
33+
"releaseBuild": false,
34+
"netlifyID": "b1e4219e-dfb6-4efa-924f-3136bbf3fa26",
35+
"deployPreview": true
36+
}
37+
]
38+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"$schema": "http://json-schema.org/schema#",
3+
"title": "FFR build and deploy config schema",
4+
"description": "A schema for the FF1 Randomizer circleci build and deploy jobs.",
5+
"type": "object",
6+
"definitions": {
7+
"branchConfig": {
8+
"required": [
9+
"branch",
10+
"longName",
11+
"shortName",
12+
"cssFile",
13+
"themeColor",
14+
"siteIcon",
15+
"releaseBuild",
16+
"netlifyID",
17+
"deployPreview"
18+
],
19+
"type": "object",
20+
"properties": {
21+
"branch": {
22+
"description": "The git branch this config is for",
23+
"type": "string"
24+
},
25+
"longName": {
26+
"description": "The long name to be used in the site manifest",
27+
"type": "string"
28+
},
29+
"shortName": {
30+
"description": "The short name to be used in the site manifest",
31+
"type": "string"
32+
},
33+
"cssFile": {
34+
"description": "The path to the version specific css file from inside /FF1Blazorizer/wwwroot/",
35+
"type": "string"
36+
},
37+
"themeColor": {
38+
"description": "The theme colour to use in the site manifest",
39+
"type": "string"
40+
},
41+
"siteIcon": {
42+
"description": "The basename used for the site icons: <basename>.ico, <basename>-192.png, <basename>-256.png, <basename>-512.png",
43+
"type": "string"
44+
},
45+
"releaseBuild": {
46+
"description": "Should this branch be built/published as a release build or a debug build",
47+
"type": "boolean"
48+
},
49+
"netlifyID": {
50+
"type": "string",
51+
"description": "The netlify id to deploy this branch to"
52+
},
53+
"deployPreview": {
54+
"type": "boolean",
55+
"description": "Should this be deployed as a preview or as a real deployment"
56+
}
57+
}
58+
}
59+
},
60+
"properties": {
61+
"branchConfig": {
62+
"type": "array",
63+
"uniqueItems": true,
64+
"items": {
65+
"$ref": "#/definitions/branchConfig"
66+
},
67+
"description": "The config for a single branch"
68+
}
69+
},
70+
"required": [
71+
"branchConfig"
72+
]
73+
}

.circleci/deploy.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
set -o errexit
3+
set -x
4+
5+
config=$(jq -r ".branchConfig | map(select(if .branch == \"default\" then true elif .branch == \"${CIRCLE_BRANCH}\" then true else false end)) | .[0]" .circleci/configs/config.json)
6+
netlifyID=$(echo "$config" | jq -r ".netlifyID")
7+
deployPreview=$(echo "$config" | jq -r ".deployPreview")
8+
if "$deployPreview"; then
9+
deploy_response=$(netlify deploy --json --dir=/root/ff1randomizer/FF1Blazorizer/output/wwwroot --site="$netlifyID")
10+
url=$(echo "$deploy_response" | jq -r ".deploy_url")
11+
12+
GH_USER=FFR_Build_And_Deploy
13+
pr_response=$(curl --location --request GET "https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls?head=$CIRCLE_PROJECT_USERNAME:$CIRCLE_BRANCH&state=open" -u $GH_USER:"$GH_API")
14+
15+
if [ "$(echo "$pr_response" | jq length)" -eq 0 ]; then
16+
echo "No PR found to update"
17+
exit 0
18+
else
19+
pr_comment_url=$(echo "$pr_response" | jq -r ".[]._links.comments.href")
20+
fi
21+
post_data='{"body": "Automatic deployment: '$url'"}'
22+
curl -X POST -H "Accept: application/vnd.github.v3+json" -H "Content-Type:application/json" "$pr_comment_url" -u $GH_USER:"$GH_API" -d "$post_data"
23+
24+
else
25+
netlify deploy --dir=/root/ff1randomizer/FF1Blazorizer/output/wwwroot --prod --site="$netlifyID"
26+
fi

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,6 @@ _Pvt_Extensions
249249

250250
# IDEA files (Rider IDE, Pycharm, etc)
251251
.idea/
252+
253+
# Local Netlify folder
254+
.netlify

FF1Blazorizer/wwwroot/cyan.ico renamed to FF1Blazorizer/wwwroot/images/icons/warmech-cyan.ico

File renamed without changes.

FF1Blazorizer/wwwroot/normal.ico renamed to FF1Blazorizer/wwwroot/images/icons/warmech-normal.ico

File renamed without changes.

FF1Blazorizer/wwwroot/red.ico renamed to FF1Blazorizer/wwwroot/images/icons/warmech-red.ico

File renamed without changes.

FF1Randomizer.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sandbox", "Sandbox\Sandbox.
1919
EndProject
2020
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".circleci", ".circleci", "{E8698844-8DA6-44D4-9290-F816B135E44E}"
2121
ProjectSection(SolutionItems) = preProject
22+
build.sh = build.sh
2223
.circleci\config.yml = .circleci\config.yml
2324
EndProjectSection
2425
EndProject
@@ -28,6 +29,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FFR.Common", "FFR.Common\FF
2829
EndProject
2930
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FFR.Common.Tests", "FFR.Common.Tests\FFR.Common.Tests.csproj", "{93FA510C-CC5D-4B74-A341-7CFE18357EF1}"
3031
EndProject
32+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "BuildConfigs", "BuildConfigs", "{C785879B-F4EB-4715-A621-91610BAF23C9}"
33+
ProjectSection(SolutionItems) = preProject
34+
ConfigSchema.json = ConfigSchema.json
35+
Main.json = Main.json
36+
EndProjectSection
37+
ProjectSection(FolderGlobals) = preProject
38+
C_5_4Users_4Steven_4dev_4FF1Randomizer_4main_1json__JsonSchema = ConfigSchema.json
39+
EndProjectSection
40+
EndProject
3141
Global
3242
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3343
Debug|Any CPU = Debug|Any CPU
@@ -68,6 +78,7 @@ Global
6878
EndGlobalSection
6979
GlobalSection(NestedProjects) = preSolution
7080
{E8698844-8DA6-44D4-9290-F816B135E44E} = {F74A70F8-A938-4587-B083-8DC615B98D23}
81+
{C785879B-F4EB-4715-A621-91610BAF23C9} = {E8698844-8DA6-44D4-9290-F816B135E44E}
7182
EndGlobalSection
7283
GlobalSection(ExtensibilityGlobals) = postSolution
7384
SolutionGuid = {B742F3AC-5BCA-469A-BBD4-A787AC019E72}

0 commit comments

Comments
 (0)