Skip to content

Commit

Permalink
Deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
Nexela committed May 15, 2019
1 parent 6a538dd commit 35ad983
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .circleci/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cookiejar.txt
test.sh
77 changes: 42 additions & 35 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,50 @@ jobs:
steps:
- checkout

# - run: git checkout gh-pages
- run: git checkout gh-pages

# - run: |
# git clone https://github.com/Afforess/Factorio-Stdlib.git /tmp/stdlib
# cd /tmp/stdlib
# git checkout release
# make quick
# cp -R .build/doc/* ~/stdlib/
- run:
name: Build Docs for gh-pages
command: |
git clone https://github.com/Afforess/Factorio-Stdlib.git /tmp/stdlib
cd /tmp/stdlib
git checkout release
make doc
cp -R .build/doc/* ~/stdlib/
# - store_artifacts:
# path: /tmp/stdlib/.build/artifacts
# destination: files
- run:
name: Commit gh-pages
command: |
git config user.email "[email protected]"
git config user.name "circleci"
git add .
git commit -am "Automatic Github Page generation"
git push
# - run: git config user.email "[email protected]"
# - run: git config user.name "circleci"
# - run: git add .
# - run: git commit -am "Automatic Github Page generation"
# - run: git push
- run: git checkout release
- run: |
NAME=$(jq -r '.name' info.json)
VERSION=$(jq -r '.version' info.json)
mkdir /tmp/upload
cd /tmp/upload
# Get a CSRF token by loading the login form
CSRF=$(curl -b cookiejar.txt -c cookiejar.txt -s https://mods.factorio.com/login | grep csrf_token | sed -r -e 's/.*value="(.*)".*/\1/')
# Authenticate with the credential secrets and the CSRF token, getting a session cookie for the authorized user
curl -b cookiejar.txt -c cookiejar.txt -s -F "csrf_token=${CSRF}" -F "username=${FACTORIO_USER}" -F "password=${FACTORIO_PASSWORD}" -o /dev/null https://mods.factorio.com/login
# Query the mod info, verify the version number we're trying to push doesn't already exist
curl -b cookiejar.txt -c cookiejar.txt -s "https://mods.factorio.com/api/mods/${NAME}/full" | jq -e ".releases[] | select(.version == \"${VERSION}\")"
# store the return code before running anything else
STATUS_CODE=$?
if [[ $STATUS_CODE -ne 4 ]]; then
echo "Release already exists, skipping"
exit 78
fi
echo "Release doesn't exist for ${TAG}, uploading"

- run: make quick

- store_artifacts:
path: ~/stdlib/.build/artifacts
destination: files

- run:
name: Export Vars
command: |
echo 'export NAME=$(jq -r '.name' info.json)' >> $BASH_ENV
echo 'export VERSION=$(jq -r '.version' info.json)' >> $BASH_ENV
echo 'FILEPATH="/root/stdlib/.build/artifacts/${NAME}_${VERSION}.zip"' >> $BASH_ENV
echo 'FILESIZE=$(stat --printf="%s" "${FILEPATH}")' >> $BASH_ENV
- run: echo ${FILEPATH} ${FILESIZE}

- run:
name: Upload Release
command: /root/stdlib/.circleci/release.sh

- run: git tag -v${VERSION}
- run: git push --tags

workflows:
version: 2
Expand All @@ -75,8 +82,8 @@ workflows:
- gh-pages
- /feature-.*/
- deploy-release:
# requires:
# - build
requires:
- build
filters:
branches:
only: release
37 changes: 37 additions & 0 deletions .circleci/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
mkdir /tmp/upload
cd /tmp/upload

echo ${FILEPATH} ${FILESIZE}
CSRF=$(curl -b cookiejar.txt -c cookiejar.txt -s https://mods.factorio.com/login | grep csrf_token | sed -r -e 's/.*value="(.*)".*/\1/')
# Authenticate with the credential secrets and the CSRF token, getting a session cookie for the authorized user
curl -b cookiejar.txt -c cookiejar.txt -s -F "csrf_token=${CSRF}" -F "username=${FACTORIO_USER}" -F "password=${FACTORIO_PASSWORD}" -o /dev/null https://mods.factorio.com/login
# Query the mod info, verify the version number we're trying to push doesn't already exist
curl -b cookiejar.txt -c cookiejar.txt -s "https://mods.factorio.com/api/mods/${NAME}/full" | jq -e ".releases[] | select(.version == \"${VERSION}\")"
# store the return code before running anything else
STATUS_CODE=$?
if [[ $STATUS_CODE -ne 4 ]]; then
echo "Release already exists, skipping"
exit 78
fi
echo "Release doesn't exist for ${VERSION}, uploading"
# Load the upload form, getting an upload token
UPLOAD_TOKEN=$(curl -b cookiejar.txt -c cookiejar.txt -s "https://mods.factorio.com/mod/${NAME}/downloads/edit" | grep token | sed -r -e "s/.*token: '(.*)'.*/\1/")
if [[ -z "${UPLOAD_TOKEN}" ]]; then
echo "Couldn't get an upload token, failed"
exit 1
fi
# Upload the file, getting back a response with details to send in the final form submission to complete the upload
UPLOAD_RESULT=$(curl -b cookiejar.txt -c cookiejar.txt -s -F "file=@${FILEPATH};type=application/x-zip-compressed" "https://direct.mods-data.factorio.com/upload/mod/${UPLOAD_TOKEN}")
# Parse 'em and stat the file for the form fields
CHANGELOG=$(echo "${UPLOAD_RESULT}" | jq -r '@uri "\(.changelog)"')
INFO=$(echo "${UPLOAD_RESULT}" | jq -r '@uri "\(.info)"')
FILENAME=$(echo "${UPLOAD_RESULT}" | jq -r '.filename')
THUMBNAIL=$(echo "${UPLOAD_RESULT}" | jq -r '.thumbnail // empty')
if [[ "${FILENAME}" == "null" ]] || [[ -z "${FILENAME}" ]]; then
echo "Upload failed"
exit 1
fi
echo "Uploaded ${NAME}_${VERSION}.zip to ${FILENAME}, submitting as new version"
# Post the form, completing the release
curl -b cookiejar.txt -c cookiejar.txt -s -X POST -d "file=&info_json=${INFO}&changelog=${CHANGELOG}&filename=${FILENAME}&file_size=${FILESIZE}&thumbnail=${THUMBNAIL}" -H "Content-Type: application/x-www-form-urlencoded" -o /dev/null "https://mods.factorio.com/mod/${NAME}/downloads/edit"
echo "Completed"
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stdlib",
"version": "1.0.3",
"version": "1.0.4",
"factorio_version": "0.17",
"title": "Factorio Standard Library",
"author": "Afforess",
Expand Down

0 comments on commit 35ad983

Please sign in to comment.