Skip to content

Instantly share code, notes, and snippets.

@rokibhasansagar
Last active July 17, 2021 14:32
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rokibhasansagar/5b065d3789ae691e0fa5c3860bf8e1a4 to your computer and use it in GitHub Desktop.

How to run Userge in Github Actions, step by step

First things first

Get the config.env file completely filled.

Use custom docker-compose file

I use This docker-compose.yml file to build and start-up my Userge Workflow.

Create New Workflow in New Repository

Make sure the branch name is main and workflow name is also main.

Plese read the comment lines inside the YAML File.

name: Serge CI

on:
  workflow_dispatch:

env:
  PAT: ${{ secrets.GH_TOKEN }}

jobs:
  build:
    runs-on: ubuntu-20.04

    steps:
      - name: Set Git Configs & Secrets
        run: |
          # Replace your github name/id and email address in the next lines
          # and add your github token as `GH_TOKEN` repo secret
          git config --global user.email "Your-github-commit-or-actual-email-address"
          git config --global user.name "Your-github-username"
          git config --global color.ui true
          git config --global credential.helper store
          echo "https://Your-github-username:${PAT}@github.com" > ~/.git-credentials
      - name: Build and Run Userge
        # the step will run for exactly 350 minutes
        timeout-minutes: 350
        continue-on-error: true
        run: |
          # Prepare: Just To Populate Workflow Output Window
          until [[ "${SECONDS_LEFT:=10}" = 0 ]]; do
            printf "Please wait %ss ...\n" "${SECONDS_LEFT}"
            sleep 0.5
            SECONDS_LEFT=$(echo "${SECONDS_LEFT} - 0.5" | bc)
          done && unset SECONDS_LEFT
          # You need account in Dockerhub
          # Put the user id as `DOCKER_USERNAME` and token (not password) as `DOCKERHUB_TOKEN` in the repo secret
          echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin &>/dev/null
          echo "::group::Prepare Repos"
          git clone YOUR-DESIRED-USERGE-CLONE-or-FORK-GIT-URL bot && cd bot
          # Use the below line if you are fetching the config from outside the repository
          curl -sL YOUR-USERGE-CONFIG-DIRECT-URL -o config.env
          # Use the custom docker-compose file modified by me
          curl -sL https://gist.github.com/rokibhasansagar/1422c565ca24a273eafee02eb31c420d/raw/Userge_Inhouse.docker-compose.yml -o docker-compose.yml
          echo "::endgroup::"
          echo "::group::Build Containers"
          # The docker container will be built first, then my slimhub_actions will clean space
          docker-compose up -d &
          sleep 20s && curl -sL https://github.com/rokibhasansagar/slimhub_actions/raw/main/cleanup.sh | bash 2>/dev/null
          echo "::endgroup::"
          echo "::group::Startup Containers"
          docker-compose logs -f
          echo "::endgroup::"
      - name: Trigger new workflow
        continue-on-error: true
        run: |
          curl -X POST --header "Authorization: token ${PAT}" https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/main.yml/dispatches -d '{"ref":"main"}'

That's all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment