Skip to content

Instantly share code, notes, and snippets.

@wispborne
Last active January 21, 2021 22:08
Show Gist options
  • Save wispborne/727d589cdc8d8e2774ce258838476d93 to your computer and use it in GitHub Desktop.
Save wispborne/727d589cdc8d8e2774ce258838476d93 to your computer and use it in GitHub Desktop.
CI setup to create ready-to-eat Starsector mods

CircleCI

Description

This setup will automate Github releases by creating a new release with a ready-for-users zipfile of your mod every time a git tag is pushed to your GitHub repository.

Steps

  1. Create a folder called .circleci in your mod directory. Add the files config.yml, zipMod.sh, and blacklist.txt to it.
  2. Open .circleci/zipmod.sh with a text editor (e.g. VS Code, Notepad++). Change the value for modFolderName. This will be the name of the mod folder.
    • It's best practice not to use spaces, e.g. "Gates-Awakened".
  3. Create an account at CircleCI and select "Sign Up With GitHub".
  4. Select "Add Projects" and choose your repository to set it up.
  5. Create a new Personal Access Token in Github - select write:packages and delete:packages (others will automatically get selected). Copy the token.
    • This will allow CircleCI to create new Github releases automatically.
  6. On CircleCI, open the Settings page for your new project, select Environment Variables, and click Add Variable. Name it "GITHUB_TOKEN" and paste the token that you had copied.
  7. That's it! The next time you push a git tag (git tag 1.0.0 && git push origin 1.0.0), CircleCI will automatically create a zip file containing your mod name with the version appended, then create a new GitHub release with the zip file.
    • You will need to update the release's changelog manually.
.psd$
.ai$
.afphoto$
^.idea
^.circleci
DO_NOT_USE
.gitignore
.gradle
^gradle
version: 2.1
jobs:
build:
docker:
- image: cibuilds/github:0.13
steps:
- checkout
- run:
name: "Create Mod Zipfile"
command: |
chmod +x ./.circleci/zipMod.sh
./.circleci/zipMod.sh
shell: /bin/sh
- store_artifacts:
path: artifacts/
- run:
name: "Publish Release on GitHub"
command: |
VERSION=$(git describe --tags)
echo "-u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./artifacts/"
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./artifacts/
workflows:
version: 2
main:
jobs:
- build:
filters:
tags:
only: /.*/ #/^\d+\.\d+\.\d+$/
branches:
ignore: /.*/
#!/bin/sh
# CHANGE ME
modFolderName="Persean-Chronicles"
version=$(git describe --tags)
zipName=$modFolderName-$version.zip
# Recreate the temp folder if it happens to be present
rm -rf "./$modFolderName-$version"
mkdir "$modFolderName-$version"
# 1. List all files in git, which uses gitignore
# 2. Remove any file matching the blacklist (eg afphoto files)
# 3. Copy to a new folder with the mod name and version
git ls-files | grep -Evf ".circleci/blacklist.txt" | while read file; do cp --parents "$file" "$modFolderName-$version"; done
# Zip the folder, then clean it up
zip -r $zipName "./$modFolderName-$version"
rm -rf "./$modFolderName-$version"
# Move the zip to the artifacts folder
mkdir -p ./artifacts
mv ./$zipName ./artifacts/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment