Skip to content

Commit

Permalink
feat: import utils actions from moderntribe/actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ggwicz committed Feb 15, 2024
1 parent 322d3b0 commit 1749f78
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 0 deletions.
22 changes: 22 additions & 0 deletions utils/commit-files/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: ModernTribe - Commit Files
description: Commit files in the same repository
author: moderntribe
inputs:
folder:
required: true
description: Folder to add files to the commit
runs:
using: composite
steps:
- name: Config Git
shell: bash
run: |
git config --global user.name "github actions modern tribe"
git config --global user.email "devops@tri.be"
- name: Commit files
shell: bash
working-directory: ${{ inputs.folder }}
run: |
git add . --force
git commit --allow-empty -m "Commiting Deploy files"
46 changes: 46 additions & 0 deletions utils/common-variables/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: 'ModernTribe - Set Variables'
description: 'Sets common environment variables needed for deploys'
author: 'moderntribe'
inputs:
app_name:
required: false
description: Dokku Original App Name
pr_number:
required: false
description: Pull Request Number
base_branch:
required: false
description: Branch
outputs:
gha-url:
description: "Github Actions URL id"
value: ${{ steps.github-runner-url.outputs.gha-url }}
branch:
description: "Branch name"
value: ${{ steps.extract-branch-name.outputs.branch }}
review-app:
description: "Review App Name"
value: ${{ steps.set-review-app.outputs.review-app }}
runs:
using: composite
steps:

- id: extract-branch-name
env:
BASE_BRANCH: ${{ inputs.base_branch }}
run: |
echo "BRANCH=$(echo ${BASE_BRANCH#refs/heads/})" >> $GITHUB_ENV
echo "##[set-output name=branch;]$(echo ${BASE_BRANCH#refs/heads/})"
shell: bash

- id: github-runner-url
run: |
echo "GHA_URL=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_ENV
echo "::set-output name=gha-url::$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID"
shell: bash

- id: set-review-app
run: |
echo "REVIEW_APP=${{ inputs.app_name }}-pr${{ inputs.pr_number }}" >> $GITHUB_ENV
echo "::set-output name=review-app::${{ inputs.app_name }}-pr${{ inputs.pr_number }}"
shell: bash
17 changes: 17 additions & 0 deletions utils/slack-message-deploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Slack Message


Usage:

```yaml
- name: Slack Notification
if: success()|| failure() || cancelled()
uses: ./.github/actions/slack
with:
branch: ${{ env.BRANCH }}
environment: ${{ env.REVIEW_APP }}
slack_webhook_url: ${{ secrets.SLACK_WEBHOOK }}
app_url: "${{ env.REVIEW_APP }}.${{ env.SERVER }}"
gha_url: ${{ env.GHA_URL }}
status: ${{ job.status }}
```
110 changes: 110 additions & 0 deletions utils/slack-message-deploy/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: 'ModernTribe - Slack Message'
description: 'Sends message to Slack Webhook.'
author: 'moderntribe'
inputs:
branch:
required: true
description: Branch being deployed
environment:
required: true
description: Environment
slack_webhook_url:
required: true
description: Incoming Webhook URL
status:
required: true
description: Job Status
app_url:
required: true
description: App URL
gha_url:
required: true
description: Github Actions Run URL

runs:
using: composite
steps:
- shell: bash
run: echo "Status=${{ inputs.status }}"

- name: Slack Success Notification
uses: slackapi/slack-github-action@v1
if: ${{ inputs.status == 'success' }}
env:
SLACK_WEBHOOK_URL: ${{ inputs.slack_webhook_url }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
with:
payload: |
{
"icon_emoji": ":rocket:",
"username": "GHA Deploy Bot",
"text": ":white_check_mark: Successful Deployment branch `${{ inputs.branch }}` to *${{ inputs.environment }}*",
"attachments": [{
"color": "good",
"title_link": "${{ inputs.app_url }}",
"fields": [{
"title": "Server URL",
"value": "${{ inputs.app_url }}"
},
{
"title": "GitHub Actions URL",
"value": "${{ inputs.gha_url }}"
}
]
}]
}
- name: Slack Failure Notification
uses: slackapi/slack-github-action@v1
if: ${{ inputs.status == 'failure' }}
env:
SLACK_WEBHOOK_URL: ${{ inputs.slack_webhook_url }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
with:
payload: |
{
"icon_emoji": ":rocket:",
"username": "GHA Deploy Bot",
"text": ":x: Failed Deployment to ${{ inputs.environment }}",
"attachments": [{
"color": "bad",
"title_link": "${{ inputs.app_url }}",
"fields": [{
"title": "Server URL",
"value": "${{ inputs.app_url }}"
},
{
"title": "GitHub Actions URL",
"value": "${{ inputs.gha_url }}"
}
]
}]
}
- name: Slack Cancel Notification
uses: slackapi/slack-github-action@v1
if: ${{ inputs.status == 'cancelled' }}
env:
SLACK_WEBHOOK_URL: ${{ inputs.slack_webhook_url }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
with:
payload: |
{
"icon_emoji": ":rocket:",
"username": "GHA Deploy Bot",
"text": ":x: Canceled Deployment to ${{ inputs.environment }}",
"attachments": [{
"color": "bad",
"title_link": "${{ inputs.app_url }}",
"fields": [{
"title": "Server URL",
"value": "${{ inputs.app_url }}"
},
{
"title": "GitHub Actions URL",
"value": "${{ inputs.gha_url }}"
}
]
}]
}
29 changes: 29 additions & 0 deletions utils/ssh-agent/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: 'ModernTribe - SSH Agent'
description: 'Setup SSH Agent'
author: 'moderntribe'
inputs:
ssh_private_key:
required: true
description: SSH Private Key
server:
required: false
description: Server
runs:
using: composite
steps:
- name: Add SSH key
shell: bash
env:
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
run: |
mkdir -p /home/runner/.ssh
install -m 600 -D /dev/null /home/runner/.ssh/id_rsa
echo "${{ inputs.ssh_private_key }}" > /home/runner/.ssh/id_rsa
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
ssh-add /home/runner/.ssh/id_rsa
- name: Add server to knownhosts
if: ${{ inputs.server != '' }}
shell: bash
run: |
ssh-keyscan -H ${{ inputs.server }} > /home/runner/.ssh/known_hosts

0 comments on commit 1749f78

Please sign in to comment.