-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cookiejar.txt | ||
test.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -75,8 +82,8 @@ workflows: | |
- gh-pages | ||
- /feature-.*/ | ||
- deploy-release: | ||
# requires: | ||
# - build | ||
requires: | ||
- build | ||
filters: | ||
branches: | ||
only: release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters