Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add action to deploy services #8

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Deploy Service

on:
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy'
required: true
default: 'dev'
services:
description: 'Services to deploy (space seperated)'
required: true

jobs:
deployment:
runs-on: ubuntu-latest
name: Deploy ${{inputs.services}} in ${{inputs.environment}}

steps:
- name: Uppercase environment
run: |
echo "ENV=`echo ${{inputs.environment}} | tr '[:lower:]' '[:upper:]'`" >>${GITHUB_ENV}

- name: call-webhook
run: |
if [ -z "${{ secrets[format('{0}_WEBHOOK_SECRET',env.ENV)] }}" ]; then
echo "::error::Secret '${{ format('{0}_WEBHOOK_SECRET',env.ENV) }}' is not set"
exit 1
fi
if [ -z "${{ secrets[format('{0}_WEBHOOK_URL',env.ENV)] }}" ]; then
echo "::error::Secret '${{ format('{0}_WEBHOOK_URL',env.ENV) }}' is not set"
exit 1
fi
if [ -z "${{ github.event.inputs.services }}" ]; then
echo "::error::'${{ github.event.inputs.services }}' is empty"
exit 1
fi

encoded_services=$(python3 -c "from urllib.parse import quote; print(quote('${{ github.event.inputs.services }}'))")
curl -X POST \
--fail-with-body -sS --no-buffer\
-H "Content-Type: application/json" \
-d '{"secret_token": "${{ secrets[format('{0}_WEBHOOK_SECRET',env.ENV)] }}"}' \
"${{ secrets[format('{0}_WEBHOOK_URL',env.ENV)] }}/hooks/deploy?services=$encoded_services"