Skip to content

Commit

Permalink
feat: trigger build only on deploy to feature branch (#8067)
Browse files Browse the repository at this point in the history
* feat: trigger build only on deploy to feature branch

* ci: add on workflow call to the called workflow

* fix: inherit secrets from the calling workflow

* fix: checkout the repo on workflow_call

* ci: wait for build to finish before triggering e2e

* fix: bring back the checkout step for "pull_request"

* chore: remove dependency on build
  • Loading branch information
Zangetsu101 authored Nov 25, 2024
1 parent 5e497eb commit b07a6c1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/build-images-from-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@
name: Publish images to Dockerhub from any branch

on:
workflow_dispatch:
workflow_call:
inputs:
branch_name:
description: Branch to build from
required: true
type: string
workflow_dispatch:
inputs:
branch_name:
default: develop
required: true
pull_request:
branches-ignore:
- 'dependabot/**'
- 'renovate/**'
description: Branch to build from
push:
branches:
- develop
Expand Down Expand Up @@ -48,6 +50,11 @@ jobs:
export VERSION=`git log -1 --pretty=format:%h`
echo "Pushing version $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
# the event_name is the event that triggered the caller workflow
# and not "workflow_call" like how it was supposed to be when
# another workflow is calling this one
if [ "${{ github.event_name }}" == 'push' ]; then
BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
elif [ "${{ github.event_name }}" == 'pull_request' ]; then
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/deploy-to-feature-environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ jobs:
}
core.setOutput('stack', slugify('${{ env.BRANCH_NAME }}'));
trigger-build:
if: ${{ (github.event_name == 'workflow_dispatch') || (!contains(github.actor, 'bot') && github.event.pull_request.head.repo.fork == false) }}
needs: generate_stack_name_and_branch
uses: ./.github/workflows/build-images-from-branch.yml
with:
branch_name: ${{ needs.generate_stack_name_and_branch.outputs.branch_name }}
secrets: inherit

trigger-e2e:
if: ${{ (github.event_name == 'workflow_dispatch') || (!contains(github.actor, 'bot') && github.event.pull_request.head.repo.fork == false) }}
runs-on: ubuntu-22.04
Expand Down

0 comments on commit b07a6c1

Please sign in to comment.