11name : " Build and Publish"
22on :
33 workflow_call :
4- workflow_dispatch :
5- workflow_run :
6- workflows : ["Run static code validation"]
7- types :
8- - completed
94concurrency :
105 group : ${{ github.workflow }}-${{ github.ref }}
116 cancel-in-progress : true
127jobs :
138 checkChanges :
149 name : Check changes
15- # Always run on workflow call and workflow dispatch
16- # Only run on workflow_run if there has been a change in the src folder,
17- # excluding markdown files
18- if : ${{
19- github.event_name == 'workflow_call' ||
20- github.event_name == 'workflow_dispatch' ||
21- (
22- github.event_name == 'workflow_run' &&
23- github.event.workflow_run.conclusion == 'success'
24- )
25- }}
2610 runs-on : ubuntu-latest
2711 outputs :
2812 continueWorkflow : ${{ steps.checkChanges.outputs.continueWorkflow }}
3216 - name : " Checkout"
3317 uses : actions/checkout@v4
3418 with :
35- ref : ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_branch || github.ref_name }}
3619 fetch-depth : 2
3720
3821 - name : " Check for changes in src folder"
5134
5235 echo "${yellow}Checking if there has been changes to source code by running git diff on the src folder excluding markdown files${reset}"
5336
54- if [ "$GITHUB_EVENT_NAME" == "workflow_run" ]; then
55- GIT_REF="${{ github.event.workflow_run.head_branch }}"
56- else
57- GIT_REF="${{ github.ref_name }}"
58- fi
59-
60- echo "Using GIT_REF: $GIT_REF"
61-
62- changes=$(git diff "$GIT_REF^" "$GIT_REF" --ignore-all-space --name-only -- src/)
37+ changes=$(git diff "${{ github.ref_name }}^" "${{ github.ref_name }}" --ignore-all-space --name-only -- src/)
6338 nonMarkdownChanges=""
6439 continueWorkflow=true
6540
9974 uses : actions/checkout@v4
10075 with :
10176 fetch-depth : 0
102- ref : ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_branch || github.ref_name }}
77+ # ref: ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_branch || github.ref_name }}
78+ ref : ${{ github.ref_name }}
10379
10480 - name : " Set Git Config"
10581 run : |
10884 git config --system --add safe.directory "$GITHUB_WORKSPACE"
10985
11086 - name : Authenticate node
87+ if : ${{ github.ref_name == 'main' }}
11188 uses : navikt/sf-platform/.github/actions/authenticateNode@main
112- if : ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.head_branch == 'main') || github.ref_name }}
11389
11490 - name : Authenticate DevHub
11591 uses : navikt/sf-platform/.github/actions/authenticateOrg@main
12399 with :
124100 devhub : " devhub"
125101 pools : " ciPlatform"
126- ref : ${{ ( github.event_name == 'workflow_run' && github.event.workflow_run.event == ' pull_request') && github.event.workflow_run.head_sha || '' }}
127- baseRef : ${{ ( github.event_name == 'workflow_run' && github.event.workflow_run.event == ' pull_request') && github.event.workflow_run.pull_requests.base .sha || '' }}
102+ ref : ${{ github.event_name == 'pull_request' && github.sha || '' }}
103+ baseRef : ${{ github.event_name == 'pull_request' && github.sha || '' }}
128104
129105 - name : Quick build
130106 uses : navikt/sf-platform/.github/actions/ciQuickBuild@main
@@ -133,30 +109,30 @@ jobs:
133109 uses : navikt/sf-platform/.github/actions/build@main
134110
135111 - name : Publish artifacts
112+ if : ${{ github.ref_name == 'main' }}
136113 uses : navikt/sf-platform/.github/actions/publishArtifact@main
137- if : ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.head_branch == 'main') || github.ref_name == 'main' }}
138114 with :
139115 nodeToken : ${{ secrets.GITHUB_TOKEN }}
140116
141117 - name : Generate Release Name
142- if : ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.head_branch == 'main') || github.ref_name == 'main' }}
118+ if : ${{ github.ref_name == 'main' }}
143119 id : generate_name
144120 run : |
145121 echo "releaseName=sf-platform_$(date +%s%3N)" >> $GITHUB_OUTPUT
146122
147123 - name : Generate Release Definition
148- if : ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.head_branch == 'main') || github.ref_name == 'main' }}
124+ if : ${{ github.ref_name == 'main' }}
149125 uses : navikt/sf-platform/.github/actions/generateReleaseDefinition@main
150126 with :
151- branchToCommitTo : ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_branch || github. ref_name }}
152- gitRef : ${{ github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github. sha }}
127+ branchToCommitTo : ${{ github.ref_name }}
128+ gitRef : ${{ github.sha }}
153129 pathToConfigFile : config/releaseConfig.yml
154130 releaseName : ${{ steps.generate_name.outputs.releaseName }}
155131 directory : " release-definition"
156132
157133 - name : Upload artifacts and logs
158- uses : navikt/sf-platform/.github/actions/uploadWorkflowArtifactsAndLogs@main
159134 if : always()
135+ uses : navikt/sf-platform/.github/actions/uploadWorkflowArtifactsAndLogs@main
160136 with :
161137 artifactName : " build-artifacts"
162138 uploadArtifacts : true
0 commit comments