Skip to content

Commit

Permalink
Refactor (ci): Utilize .build.state artifact (startersclan#118)
Browse files Browse the repository at this point in the history
Co-authored-by: leo <[email protected]>
Co-authored-by: joe <[email protected]>
  • Loading branch information
joeltimothyoh and leojonathanoh authored Mar 7, 2023
1 parent c5ef327 commit a64d202
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
10 changes: 8 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,18 @@ jobs:
no_output_timeout: 40m
command: |
export PIPELINE="$CIRCLE_BRANCH"
./build.sh && echo 'success' > .build-status || ( echo 'failed' > .build-status && exit 1 )
set +e
./build.sh
if [ $? = 0 ]; then
echo BUILD_STATUS=success >> .build.state
else
echo BUILD_STATUS=failed >> .build.state
exit 1
fi
- run:
name: Send notification
when: always
command: |
export BUILD_STATUS=$( cat .build-status )
export CI_JOB_ID="$CIRCLE_BUILD_NUM"
export CI_PROJECT_NAMESPACE="$CIRCLE_PROJECT_USERNAME"
export CI_PROJECT_NAME="$CIRCLE_PROJECT_REPONAME"
Expand Down
12 changes: 9 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ build-image:
script:
- |
export PIPELINE="$CI_COMMIT_BRANCH"
./build.sh && echo 'success' > .build-status || ( echo 'failed' > .build-status && exit 1 )
set +e
./build.sh
if [ $? = 0 ]; then
echo BUILD_STATUS=success >> .build.state
else
echo BUILD_STATUS=failed >> .build.state
exit 1
fi
artifacts:
paths:
- .build-status
- .build.state
when: always
expire_in: never

Expand All @@ -33,6 +40,5 @@ send-notification:
script:
- |
apk add --no-cache curl
export BUILD_STATUS=$( cat .build-status )
export X_CI_WEBHOOK_SECRET_HEADER="x-gitlab-webhook-secret: $X_GITLAB_WEBHOOK_SECRET"
./notify.sh
17 changes: 15 additions & 2 deletions notify.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/sh

# Process job variables
BUILD_STATUS=${BUILD_STATUS:?err}
GAME_VERSION=${GAME_VERSION:-}
APPID=${APPID:-}
CLIENT_APPID=${CLIENT_APPID:-}
Expand All @@ -15,6 +14,15 @@ NO_TEST=${NO_TEST:-}
NO_PUSH=${NO_PUSH:-}
STEAM_LOGIN=${STEAM_LOGIN:-}

# Read build state file
echo "Reading .build.state file"
. ./.build.state

# Process build state variables
BUILD_STATUS=${BUILD_STATUS:?err}
BASE_SIZE=${BASE_SIZE:-0}
LAYERED_SIZE=${LAYERED_SIZE:-0}

# Send notification
date
echo 'Sending notification'
Expand All @@ -38,7 +46,12 @@ BODY=$( cat <<EOF
"NO_PUSH": "$NO_PUSH",
"STEAM_LOGIN": "$STEAM_LOGIN"
},
"status": "$BUILD_STATUS"
"status": "$BUILD_STATUS",
"state": {
"BUILD_STATUS": "$BUILD_STATUS",
"BASE_SIZE": "$BASE_SIZE",
"LAYERED_SIZE": "$LAYERED_SIZE"
}
}
EOF
)
Expand Down

0 comments on commit a64d202

Please sign in to comment.