Skip to content

Git Runner Deployer

Git Runner Deployer #6

name: Git Runner Deployer
on:
workflow_dispatch:
inputs:
playground-account-name:
description: "Enter playground account name"
required: true
env-name:
description: "Enter environment name (Leave blank if you want to use default)"
env:
PLAYGROUND_PAT: ${{ secrets.PLAYGROUND_PAT }}
GITHUB_PAT: ${{ secrets.GH_PAT }}
jobs:
create-napptive-env:
name: Create napptive environment
runs-on: ubuntu-latest
env:
ENV: ${{ github.event.inputs.env-name }}
PLAYGROUND_ACCOUNT_NAME: ${{ github.event.inputs.playground-account-name }}
ORG: ${{ github.repository_owner }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install jq
run: sudo apt install jq
- name: Install napptive CLI
shell: bash
run: curl -O https://storage.googleapis.com/artifacts.playground.napptive.dev/installer.sh && bash installer.sh
- name: Login using PAT
shell: bash
run: playground login --pat
- name: Request Runner token
shell: bash
run: |
RESPONSE=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_PAT" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/orgs/$ORG/actions/runners/registration-token)
echo $RESPONSE
echo "TOKEN=$(echo $RESPONSE | jq -r '.token')" >> $GITHUB_ENV
- name: Replace token in param file
shell: bash
run: |
sed -i "s/__TOKEN__/$TOKEN/g" param-file.yaml
sed -i "s/__ORGANIZATION__/$ORG/g" param-file.yaml
- name: Use env if not empty
shell: bash
run: |
if [ $ENV ]; then
playground env use $PLAYGROUND_ACCOUNT_NAME/$ENV
fi
if [ $? -ne 0 ]; then
playground env create "$PLAYGROUND_ACCOUNT_NAME/$ENV"
echo "ENVIRONMENT CREATED: $PLAYGROUND_ACCOUNT_NAME/$ENV"
playground env use $PLAYGROUND_ACCOUNT_NAME/$ENV
fi
- name: Deploy app
shell: bash
run: |
playground catalog deploy napptive/github-runner:2.298.2 --setParametersFromFile param-file.yaml
- name: Wait for app to deploy
shell: bash
run: |
playground apps wait github-runner
launch-unit-tests:
needs: create-napptive-env
runs-on: napptive
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: "18"
- name: Install dependencies
run: npm ci
- name: Run unit tests
run: npm run test
cleanup-runner:
needs: [create-napptive-env, launch-unit-tests]
runs-on: ubuntu-latest
steps:
- name: Remove Runner
uses: napptive-actions/playground-github-action@v6.1.0
continue-on-error: true
with:
cmd: "apps remove github-runner"
environment: ${{ github.event.inputs.env-name }}
- name: Remove environment
uses: napptive-actions/playground-github-actions@v3.0.1
continue-on-error: true
with:
cmd: "env remove $PLAYGROUND_ACCOUNT_NAME/$ENV"