-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import Workflow Files from
@moderntribe/actions
(#1)
We are using actions from [the @moderntribe/actions repo](https://github.com/moderntribe/actions) in a number of places in StellarWP — the `square1/composer` action, for example. I thought it was worthwhile to import these files into this StellarWP repo for more straightforward governance [i.e. "keeping it in one org"], and just in case there would be some scenario where we lost access to the repo. https://app.asana.com/0/1206581172125548/1206616396718524/f
- Loading branch information
Showing
9 changed files
with
331 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Reusable Workflow - Create Review App | ||
on: | ||
workflow_call: | ||
inputs: | ||
app_name: | ||
required: true | ||
type: string | ||
description: Dokku Original App Name | ||
pr_number: | ||
required: false | ||
type: string | ||
description: Pull Request Number | ||
secrets: | ||
github_pat_token: | ||
required: true | ||
server: | ||
required: true | ||
ssh_private_key: | ||
required: true | ||
|
||
jobs: | ||
create_review_app: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set common variables | ||
uses: moderntribe/actions/utils/common-variables@v1 | ||
with: | ||
app_name: ${{ inputs.app_name }} | ||
pr_number: ${{ inputs.pr_number }} | ||
|
||
- name: Setup SSH | ||
uses: moderntribe/actions/utils/ssh-agent@v1 | ||
with: | ||
ssh_private_key: ${{ secrets.ssh_private_key }} | ||
server: ${{ secrets.server }} | ||
|
||
- name: Create review app ${{ inputs.review_app_name }} | ||
uses: moderntribe/actions/dokku/create-review-app@v1 | ||
with: | ||
app_name: ${{ inputs.app_name }} | ||
review_app_name: ${{ env.REVIEW_APP }} | ||
server: ${{ secrets.server }} | ||
github_pat_token: ${{ secrets.github_pat_token }} | ||
gha_url: ${{ env.GHA_URL }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: Reusable Workflow - Delete Review App | ||
on: | ||
workflow_call: | ||
inputs: | ||
app_name: | ||
required: true | ||
type: string | ||
description: Dokku Original App Name | ||
pr_number: | ||
required: false | ||
type: string | ||
description: Pull Request Number | ||
secrets: | ||
github_pat_token: | ||
required: true | ||
server: | ||
required: true | ||
|
||
jobs: | ||
delete_review_app: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set common variables | ||
uses: moderntribe/actions/utils/common-variables@v1 | ||
with: | ||
app_name: ${{ inputs.app_name }} | ||
pr_number: ${{ inputs.pr_number }} | ||
|
||
- name: Delete review app ${{ env.REVIEW_APP }} | ||
uses: moderntribe/actions/dokku/delete-review-app@v1 | ||
with: | ||
app_name: ${{ inputs.app_name }} | ||
review_app_name: ${{ env.REVIEW_APP }} | ||
server: ${{ secrets.server }} | ||
github_pat_token: ${{ secrets.github_pat_token }} | ||
gha_url: ${{ env.GHA_URL }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
.vscode | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: 'ModernTribe - Git Deploy' | ||
description: 'Deploy to a Git repository' | ||
author: 'moderntribe' | ||
inputs: | ||
git_url: | ||
required: true | ||
description: Git Url | ||
branch: | ||
required: false | ||
default: master | ||
description: Branch being deployed | ||
folder: | ||
required: false | ||
default: . | ||
description: Git folder path | ||
runs: | ||
using: composite | ||
steps: | ||
- name: Deploy to ${{ inputs.app }} | ||
shell: bash | ||
working-directory: ${{ inputs.folder }} | ||
run: | | ||
git remote add deploy_server ${{ inputs.git_url }} | ||
git push deploy_server ${{ inputs.branch }}:master --force |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}" | ||
} | ||
] | ||
}] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |