From f0e0644565dcd471e222ddcebd627cf7caec6293 Mon Sep 17 00:00:00 2001 From: Abhinav-26 Date: Wed, 31 Jul 2024 12:30:40 +0530 Subject: [PATCH] github actions plugin --- .github/workflows/image-push-devtron.yml | 23 +++++++++++ action.yaml | 45 ++++++++++++++++++++++ scripts/deploy.sh | 49 ++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 .github/workflows/image-push-devtron.yml create mode 100644 action.yaml create mode 100755 scripts/deploy.sh diff --git a/.github/workflows/image-push-devtron.yml b/.github/workflows/image-push-devtron.yml new file mode 100644 index 0000000..3745225 --- /dev/null +++ b/.github/workflows/image-push-devtron.yml @@ -0,0 +1,23 @@ +name: Push Image to Devtron + +on: [push] + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Push Image to Devtron + uses: ./ # Uses the local action defined in the repository + with: + DEVTRON_URL: ${{ secrets.DEVTRON_URL }} + DEVTRON_API_TOKEN: ${{ secrets.DEVTRON_API_TOKEN }} + IMAGE: ${{ secrets.IMAGE }} + ID: ${{ secrets.ID }} + COMMIT_HASH: ${{ secrets.COMMIT_HASH }} + MESSAGE: ${{ secrets.MESSAGE }} + AUTHOR_NAME: ${{ secrets.AUTHOR_NAME }} + COMMIT_TIME: ${{ secrets.COMMIT_TIME }} \ No newline at end of file diff --git a/action.yaml b/action.yaml new file mode 100644 index 0000000..f2e1d75 --- /dev/null +++ b/action.yaml @@ -0,0 +1,45 @@ +name: 'Devtron Deploy Action' +description: 'An action to deploy using Devtron with optional commit details' +author: 'Your Name' +inputs: + DEVTRON_URL: + description: 'The URL of the Devtron instance' + required: true + DEVTRON_API_TOKEN: + description: 'The API token for Devtron' + required: true + IMAGE: + description: 'The Docker image to be deployed' + required: true + ID: + description: 'The ID for the Devtron orchestrator' + required: true + COMMIT_HASH: + description: 'The commit hash (optional)' + required: false + MESSAGE: + description: 'The commit message (optional)' + required: false + AUTHOR_NAME: + description: 'The author name of the commit (optional)' + required: false + COMMIT_TIME: + description: 'The commit time (optional)' + required: false +runs: + using: 'composite' + steps: + - run: ./scripts/deploy.sh + shell: bash + env: + DEVTRON_URL: ${{ inputs.DEVTRON_URL }} + DEVTRON_API_TOKEN: ${{ inputs.DEVTRON_API_TOKEN }} + IMAGE: ${{ inputs.IMAGE }} + ID: ${{ inputs.ID }} + COMMIT_HASH: ${{ inputs.COMMIT_HASH }} + MESSAGE: ${{ inputs.MESSAGE }} + AUTHOR_NAME: ${{ inputs.AUTHOR_NAME }} + COMMIT_TIME: ${{ inputs.COMMIT_TIME }} +branding: + icon: 'rocket' + color: 'blue' \ No newline at end of file diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 0000000..69d84d5 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +set -e + +DEVTRON_URL=${DEVTRON_URL} +DEVTRON_API_TOKEN=${DEVTRON_API_TOKEN} +IMAGE=${IMAGE} +ID=${ID} +COMMIT_HASH=${COMMIT_HASH} +MESSAGE=${MESSAGE} +AUTHOR_NAME=${AUTHOR_NAME} +COMMIT_TIME=${COMMIT_TIME} + +if [ -z "$COMMIT_HASH" ]; then + COMMIT_HASH="" +fi + +if [ -z "$MESSAGE" ]; then + MESSAGE="" +fi + +if [ -z "$AUTHOR_NAME" ]; then + AUTHOR_NAME="" +fi + +if [ -z "$COMMIT_TIME" ]; then + COMMIT_TIME="" +fi + +jsonData=$(cat <