Skip to content

Commit

Permalink
github actions plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhinav-26 committed Jul 31, 2024
1 parent 0ddd5a8 commit f0e0644
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/image-push-devtron.yml
Original file line number Diff line number Diff line change
@@ -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 }}
45 changes: 45 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
@@ -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'
49 changes: 49 additions & 0 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
{
"dockerImage": "$IMAGE",
"ciProjectDetails": [
{
"commitHash": "$COMMIT_HASH",
"message": "$MESSAGE",
"author": "$AUTHOR_NAME",
"commitTime": "$COMMIT_TIME"
}
]
}
EOF
)

curl --location --request POST \
"https://${DEVTRON_URL}/orchestrator/webhook/ext-ci/${ID}" \
--header 'Content-Type: application/json' \
--header "api-token: ${DEVTRON_API_TOKEN}" \
--data-raw "${jsonData}"

0 comments on commit f0e0644

Please sign in to comment.