Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
TamimiGitHub committed May 16, 2024
0 parents commit 2e97e31
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 0 deletions.
88 changes: 88 additions & 0 deletions .github/workflows/config_push_preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# This workflow will be triggered on every PR on the main branch
# Note : if the asyncapi file is not present, the job is canceled

# To get started, configure the following in your repos secrets https://docs.github.com/en/actions/security-guides/encrypted-secrets
# SOLACE_CLOUD_TOKEN: Solace Cloud Token

name: Config Push Preview
on:
pull_request:
branches: [ main ]

env:
EVENT_MESH_NAME: us-central-solace-Prod
PREVIEW_ONLY: TRUE

jobs:
plan:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Get asyncapi file in the commit
id: changed_files
uses: tj-actions/changed-files@v40
with:
files: |
asyncapi*
- name: Read asyncapi content
id: asyncapi
run: |
for file in ${{ steps.changed_files.outputs.all_changed_files }}; do
if [[ ( ${file} == *.yaml ) || ( ${file} == *.yml ) || ( ${file} == *.json ) ]]
then
echo 'asyncFile<<EOF' >> $GITHUB_OUTPUT
echo $(cat $file) >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
fi
done
- name: Extract Application Version ID from asyncapiFile
if: ${{ steps.asyncapi.outputs.asyncFile }}
uses: tmelliottjr/[email protected]
id: epApplicationVersionId
with:
regex: '(?<=x-ep-application-version-id\\": \\")(.*?)(?=\\")'
flags: "gm"
input: ${{steps.asyncapi.outputs.asyncFile}}

- name: Generate Preview Application Version Deployment Plan
if: ${{ steps.epApplicationVersionId.outputs.resultString }}
id: plan
uses: SolaceDev/[email protected]
with:
SOLACE_CLOUD_TOKEN: ${{ secrets.SOLACE_CLOUD_TOKEN }}
APPLICATION_VERSION_ID: ${{ steps.epApplicationVersionId.outputs.resultString }}
EVENT_MESH_NAME: ${{ env.EVENT_MESH_NAME }}
PREVIEW_ONLY: ${{ env.PREVIEW_ONLY }}

- name: PR Comment with Deployment Preview
uses: actions/github-script@v6
if: github.event_name == 'pull_request'
env:
PLAN: "${{ steps.plan.outputs.deployment_plan }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// 1. Prepare format of the comment
const output = `#### Application Deployment Plan 📖\`${{ steps.plan.outcome }}\`
<details><summary>Show Plan</summary>

\`\`\`\n
${process.env.PLAN}
\`\`\`

</details>

*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\` *`;

// 2. Create PR comment with the deployment plan
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
56 changes: 56 additions & 0 deletions .github/workflows/config_push_preview_deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This workflow will be triggered on every merge on the main branch
# Note : if the asyncapi file is not present, the job is canceled

# To get started, configure the following in your repos secrets https://docs.github.com/en/actions/security-guides/encrypted-secrets
# SOLACE_CLOUD_TOKEN: Solace Cloud Token

name: Config Push Deploy
on:
push:
branches: [ main ]

env:
EVENT_MESH_NAME: us-central-solace-Prod

jobs:
config-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Get asyncapi file in the commit
id: changed_files
uses: tj-actions/changed-files@v40
with:
files: |
asyncapi*
- name: Read asyncapi content
id: asyncapi
run: |
for file in ${{ steps.changed_files.outputs.all_changed_files }}; do
if [[ ( ${file} == *.yaml ) || ( ${file} == *.yml ) || ( ${file} == *.json ) ]]
then
echo 'asyncFile<<EOF' >> $GITHUB_OUTPUT
echo $(cat $file) >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
fi
done
- name: Extract Application Version ID from asyncapiFile
if: ${{ steps.asyncapi.outputs.asyncFile }}
uses: tmelliottjr/[email protected]
id: epApplicationVersionId
with:
regex: '(?<=x-ep-application-version-id\\": \\")(.*?)(?=\\")'
flags: "gm"
input: ${{steps.asyncapi.outputs.asyncFile}}

- name: Promote Application Version
if: ${{ steps.epApplicationVersionId.outputs.resultString }}
uses: SolaceDev/[email protected]
with:
SOLACE_CLOUD_TOKEN: ${{ secrets.SOLACE_CLOUD_TOKEN }}
APPLICATION_VERSION_ID: ${{ steps.epApplicationVersionId.outputs.resultString }}
EVENT_MESH_NAME: ${{ env.EVENT_MESH_NAME }}
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*

# IDE config
.project
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Github Workflow configuration for Spring Cloud Stream with Asyncapi
This repo will have the github workflow needed to plan, provision, and promote a Spring Cloud Stream application using Event Portal, Event Broker, and AsyncaPI

## Things to note
- This workflow assumes an asyncapi.yml file in the root of the directory.
- Make sure github actions is enabled in your repo
- Settings --> Actions --> General --> Allow all actions and reusable workflows
- Settings --> Actions --> General --> Workflow permissions --> Enable read/write
- Confiure the secrets in your repo as per the [workflow files](.github/workflows)
- Edit this readme to match your project description

0 comments on commit 2e97e31

Please sign in to comment.