Skip to content

custom_event

custom_event #34

name: API Triggered Workflow
on:
repository_dispatch:
types: [custom_event]
jobs:
build:
runs-on: ubuntu-latest
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup Terraform
uses: hashicorp/setup-terraform@v1
- name: Initialize Terraform
working-directory: ./terraform
run: terraform init
- name: Execute Terraform based on payload
working-directory: ./terraform
run: |
case "${{ github.event.client_payload.action }}" in
start)
terraform apply -auto-approve -var="game_state=running" -var="slack_token=${{ secrets.SLACK_BOT_OAUTH_TOKEN }}" -var="github_token=${{ secrets.GH_ACTIONS_TOKEN }}"
;;
stop)
terraform apply -auto-approve -var="game_state=stopped" -var="slack_token=${{ secrets.SLACK_BOT_OAUTH_TOKEN }}" -var="github_token=${{ secrets.GH_ACTIONS_TOKEN }}"
;;
status)
terraform output -json
;;
*)
echo "Unknown action: ${{ github.event.client_payload.action }}"
exit 1
;;
esac
# - name: Print the payload
# run: echo '${{ toJson(github.event.client_payload) }}' | jq .
# Add more steps as needed...