feat: adding new workflows for aggregated docker build and preview en… #3
Workflow file for this run
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
# Deploys a temporary environment for testing a version of the code when a pull request is created / updated with a 'deploy-pr' label | |
name: Deploy PR Environment | |
concurrency: | |
group: "deploy-${{ github.event.pull_request.head.ref }}" | |
cancel-in-progress: false | |
on: | |
workflow_dispatch: | |
pull_request: | |
types: [ labeled, synchronize ] | |
permissions: | |
id-token: write | |
contents: write | |
pull-requests: write | |
env: | |
REF: ${{ github.event_name == 'workflow_dispatch' && github.ref_name || github.event_name == 'pull_request' && github.event.pull_request.head.ref }} | |
jobs: | |
deploy-dev-pr-environment: | |
if: contains(github.event.pull_request.labels.*.name, 'deploy-pr') | |
runs-on: ubuntu-latest | |
outputs: | |
env_name: ${{ steps.env-name.outputs.PR_ENV_NAME }} | |
ref: ${{ steps.clean-ref.outputs.ref }} | |
steps: | |
- name: Clean Ref | |
id: clean-ref | |
shell: bash | |
run: | | |
BRANCH_NAME=${{ env.REF }} | |
CLEAN_BRANCH_NAME=${BRANCH_NAME#refs/heads/} | |
echo "ref=$CLEAN_BRANCH_NAME" >> $GITHUB_OUTPUT | |
- name: Checkout the Tool and actions | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ steps.clean-ref.outputs.ref }} | |
fetch-depth: 1 | |
- name: "Sanitize ENV name" | |
id: sanitize_env | |
shell: bash | |
run: | | |
SANITIZED_BRANCH_NAME=$(echo -n ${{ steps.clean-ref.outputs.ref }} | tr "/" "-") | |
echo "Sanitized branch name: $SANITIZED_BRANCH_NAME" | |
TRIMMED_BRANCH_NAME=$(echo -n "$SANITIZED_BRANCH_NAME" | cut -c 1-8) | |
echo "sanitized_env_name=$SANITIZED_BRANCH_NAME" >> $GITHUB_OUTPUT; | |
echo "trimmed_env_name=$TRIMMED_BRANCH_NAME" >> $GITHUB_OUTPUT; | |
- name: Environment deployment | |
id: env-name | |
run: | | |
echo "deploying environment" | |
echo "PR_ENV_NAME=${{ steps.sanitize_env.outputs.trimmed_env_name }}" >> $GITHUB_ENV | |
echo "PR_ENV_NAME=${{ steps.sanitize_env.outputs.trimmed_env_name }}" >> $GITHUB_OUTPUT | |
build-wf-service: | |
needs: deploy-dev-pr-environment | |
uses: ./.github/workflows/build-push-docker-images.yml | |
with: | |
registry: ghcr.io/${{ github.repository_owner }} | |
context: services/workflows-service | |
image_name: workflows-service | |
ref: ${{ needs.deploy-dev-pr-environment.outputs.ref }} | |
tag: ${{ needs.deploy-dev-pr-environment.outputs.env_name }} | |
build-backoffice: | |
needs: deploy-dev-pr-environment | |
uses: ./.github/workflows/build-push-docker-images.yml | |
with: | |
registry: ghcr.io/${{ github.repository_owner }} | |
context: apps/backoffice-v2 | |
image_name: backoffice | |
ref: ${{ needs.deploy-dev-pr-environment.outputs.ref }} | |
tag: ${{ needs.deploy-dev-pr-environment.outputs.env_name }} | |
build-kyb: | |
needs: deploy-dev-pr-environment | |
uses: ./.github/workflows/build-push-docker-images.yml | |
with: | |
registry: ghcr.io/${{ github.repository_owner }} | |
context: apps/kyb-app | |
image_name: kyb-app | |
ref: ${{ needs.deploy-dev-pr-environment.outputs.ref }} | |
tag: ${{ needs.deploy-dev-pr-environment.outputs.env_name }} | |
build-dashboard: | |
needs: deploy-dev-pr-environment | |
uses: ./.github/workflows/build-push-docker-images.yml | |
with: | |
registry: ghcr.io/${{ github.repository_owner }} | |
context: apps/workflows-dashboard | |
image_name: workflows-dashboard | |
ref: ${{ needs.deploy-dev-pr-environment.outputs.ref }} | |
tag: ${{ needs.deploy-dev-pr-environment.outputs.env_name }} | |
deploy-preview: | |
needs: [deploy-dev-pr-environment,build-wf-service,build-backoffice,build-kyb,build-dashboard] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Trigger workflow in another repo | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GIT_TOKEN }} | |
script: | | |
await github.rest.repos.createDispatchEvent({ | |
owner: 'ballerine-io', | |
repo: 'cloud-infra-config', | |
event_type: 'deploy-preview', | |
client_payload: { | |
'ref': '${{ needs.deploy-dev-pr-environment.outputs.env_name }}' | |
} | |
}); |