Skip to content

Commit 372b59b

Browse files
committed
Tidy up the build, and skip job if pr got edited, but there were no checkbox changes
1 parent bffd32c commit 372b59b

File tree

1 file changed

+50
-47
lines changed

1 file changed

+50
-47
lines changed

.github/workflows/build.yml

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,75 @@
11
name: Build
22
on:
33
pull_request:
4-
types: [opened, synchronize, edited]
4+
types: [ opened, synchronize, edited ]
55
push:
6-
branches: [main]
6+
branches: [ main ]
77
workflow_dispatch:
88

99
jobs:
10-
1110
configuration:
1211
name: Configure job parameters
13-
runs-on: [self-hosted]
12+
runs-on: [ self-hosted ]
1413
concurrency:
1514
group: ${{ github.head_ref || github.ref }}-configuration
1615
cancel-in-progress: true
1716
outputs:
18-
is_main_branch: ${{ steps.output.outputs.is_main_branch }}
19-
version: ${{ steps.output.outputs.version }}
20-
preview_enable: ${{ steps.output.outputs.preview_enable }}
21-
preview_infra_provider: ${{ steps.output.outputs.preview_infra_provider }}
22-
with_github_actions: ${{ steps.output.outputs.with_github_actions }}
23-
build_no_cache: ${{ steps.output.outputs.build_no_cache }}
24-
build_no_test: ${{ steps.output.outputs.build_no_test }}
17+
is_main_branch: ${{ (github.head_ref || github.ref) == 'refs/heads/main' }}
18+
version: ${{ steps.branches.outputs.sanitized-branch-name }}-gha.${{github.run_number}}
19+
with_github_actions: ${{ contains(github.event.pull_request.body, '[x] /werft with-github-actions') }}
20+
preview_enable: ${{ contains(github.event.pull_request.body, '[x] /werft with-preview') }}
21+
preview_infra_provider: ${{ contains(github.event.pull_request.body, '[X] /werft with-gce-vm') && 'gce' || 'harvester' }}
22+
build_no_cache: ${{ contains(github.event.pull_request.body, '[x] leeway-no-cache') }}
23+
build_no_test: ${{ contains(github.event.pull_request.body, '[x] /werft no-test') }}
2524
build_leeway_target: ${{ steps.output.outputs.build_leeway_target }}
26-
with_large_vm: ${{ steps.output.outputs.with_large_vm }}
27-
publish_to_npm: ${{ steps.output.outputs.publish_to_npm }}
28-
publish_to_jbmp: ${{ steps.output.outputs.publish_to_jbmp }}
29-
with_ws_manager_mk2: ${{ steps.output.outputs.with_ws_manager_mk2 }}
30-
with_dedicated_emulation: ${{ steps.output.outputs.with_dedicated_emulation }}
31-
with_ee_license: ${{ steps.output.outputs.with_ee_license }}
32-
with_slow_database: ${{ steps.output.outputs.with_slow_database }}
33-
analytics: ${{ steps.output.outputs.analytics }}
25+
with_large_vm: ${{ contains(github.event.pull_request.body, '[X] /werft with-large-vm') }}
26+
publish_to_npm: ${{ contains(github.event.pull_request.body, '[X] /werft publish-to-npm') }}
27+
publish_to_jbmp: ${{ contains(github.event.pull_request.body, '[X] /werft publish-to-jb-marketplace') }}
28+
with_ws_manager_mk2: ${{ contains(github.event.pull_request.body, '[X] with-ws-manager-mk2') }}
29+
with_dedicated_emulation: ${{ contains(github.event.pull_request.body, '[X] with-dedicated-emulation') }}
30+
with_ee_license: ${{ contains(github.event.pull_request.body, '[X] with-ee-license') }}
31+
with_slow_database: ${{ contains(github.event.pull_request.body, '[X] with-slow-database') }}
32+
analytics: ${{ contains(github.event.pull_request.body, '[X] analytics') }}
3433
workspace_feature_flags: ${{ steps.output.outputs.workspace_feature_flags }}
34+
pr_no_diff_skip: ${{ steps.pr-diff.outputs.pr_no_diff_skip }}
3535
steps:
3636
- name: "Determine Branch"
3737
id: branches
3838
uses: transferwise/sanitize-branch-name@v1
39+
# If the PR got edited, but no checkbox changes occurred, we don't want to run the whole build
40+
# Therefore we set a flag and use it to skip the next jobs
41+
- name: "Check PR diff"
42+
id: pr-diff
43+
env:
44+
PR_DESC: '${{ github.event.pull_request.body }}'
45+
OLD_BODY: '${{ github.event.changes.body.from }}'
46+
if: (github.event_name == 'pull_request' && github.event.action == 'edited')
47+
run: |
48+
if ! diff <(echo "$OLD_BODY") <(echo "$PR_DESC") | grep -e '\[x\]' -e '\[X\]'; then
49+
echo "pr_no_diff_skip=true" >> $GITHUB_OUTPUT
50+
fi
3951
- name: "Set outputs"
4052
id: output
4153
env:
4254
PR_DESC: '${{ github.event.pull_request.body }}'
4355
shell: bash
4456
run: |
4557
{
46-
echo "is_main_branch=${{ (github.head_ref || github.ref) == 'refs/heads/main' }}"
47-
echo "version=${{ steps.branches.outputs.sanitized-branch-name }}-gha.${{github.run_number}}"
48-
echo "with_github_actions=${{ contains(github.event.pull_request.body, '[x] /werft with-github-actions') }}"
49-
echo "preview_enable=${{ contains(github.event.pull_request.body, '[x] /werft with-preview') }}"
50-
echo "preview_infra_provider=${{ contains(github.event.pull_request.body, '[X] /werft with-gce-vm') && 'gce' || 'harvester' }}"
51-
echo "build_no_cache=${{ contains(github.event.pull_request.body, '[x] leeway-no-cache') }}"
52-
echo "build_no_test=${{ contains(github.event.pull_request.body, '[x] /werft no-test') }}"
5358
echo "build_leeway_target=$(echo "$PR_DESC" | sed -n -e 's/^.*leeway-target=//p' | sed 's/\r$//')"
54-
echo "with_large_vm=${{ contains(github.event.pull_request.body, '[X] /werft with-large-vm') }}"
55-
echo "publish_to_npm=${{ contains(github.event.pull_request.body, '[X] /werft publish-to-npm') }}"
56-
echo "publish_to_jbmp=${{ contains(github.event.pull_request.body, '[X] /werft publish-to-jb-marketplace') }}"
57-
echo "with_ws_manager_mk2=${{ contains(github.event.pull_request.body, '[X] with-ws-manager-mk2') }}"
58-
echo "with_dedicated_emulation=${{ contains(github.event.pull_request.body, '[X] with-dedicated-emulation') }}"
59-
echo "with_ee_license=${{ contains(github.event.pull_request.body, '[X] with-ee-license') }}"
60-
echo "with_slow_database=${{ contains(github.event.pull_request.body, '[X] with-slow-database') }}"
61-
echo "analytics=${{ contains(github.event.pull_request.body, '[X] analytics') }}"
6259
echo "workspace_feature_flags=$(echo "$PR_DESC" | grep -oP '(?<=\[X\] workspace-feature-flags).*')"
6360
} >> $GITHUB_OUTPUT
6461
6562
build-previewctl:
6663
name: Build previewctl
67-
if: ${{ needs.configuration.outputs.is_main_branch == 'true' || needs.configuration.outputs.preview_enable == 'true' }}
68-
needs: [configuration]
64+
if: |
65+
(needs.configuration.outputs.pr_no_diff_skip != 'true') &&
66+
(needs.configuration.outputs.is_main_branch == 'true' || needs.configuration.outputs.preview_enable == 'true')
67+
needs: [ configuration ]
6968
concurrency:
7069
group: ${{ github.head_ref || github.ref }}-build-previewctl
7170
# see comment in build-gitpod below for context
7271
cancel-in-progress: ${{ needs.configuration.outputs.is_main_branch == 'false' }}
73-
runs-on: [self-hosted]
72+
runs-on: [ self-hosted ]
7473
container:
7574
image: eu.gcr.io/gitpod-core-dev/dev/dev-environment:kylos101-kubecdl-home.1
7675
outputs:
@@ -99,9 +98,11 @@ jobs:
9998
echo "previewctl_hash=$(leeway describe dev/preview/previewctl:docker -Dversion="${{needs.configuration.outputs.version}}" -t '{{ .Metadata.Version }}')" >> $GITHUB_OUTPUT
10099
101100
infrastructure:
102-
needs: [configuration, build-previewctl]
103-
if: ${{ needs.configuration.outputs.preview_enable == 'true' && needs.configuration.outputs.with_github_actions == 'true' }}
104-
runs-on: [self-hosted]
101+
needs: [ configuration, build-previewctl ]
102+
if: |
103+
(needs.configuration.outputs.pr_no_diff_skip != 'true') &&
104+
(needs.configuration.outputs.preview_enable == 'true' && needs.configuration.outputs.with_github_actions == 'true')
105+
runs-on: [ self-hosted ]
105106
concurrency:
106107
group: ${{ github.head_ref || github.ref }}-infrastructure
107108
steps:
@@ -118,9 +119,11 @@ jobs:
118119

119120
build-gitpod:
120121
name: Build Gitpod
121-
needs: [configuration]
122-
if: ${{ needs.configuration.outputs.is_main_branch == 'true' || needs.configuration.outputs.with_github_actions == 'true' }}
123-
runs-on: [self-hosted]
122+
needs: [ configuration ]
123+
if: |
124+
(needs.configuration.outputs.pr_no_diff_skip != 'true') &&
125+
(needs.configuration.outputs.is_main_branch == 'true' || needs.configuration.outputs.with_github_actions == 'true')
126+
runs-on: [ self-hosted ]
124127
concurrency:
125128
group: ${{ github.head_ref || github.ref }}-build-gitpod
126129
# For the main branch we always want the build job to run to completion
@@ -243,8 +246,8 @@ jobs:
243246
244247
install:
245248
name: "Install Gitpod"
246-
needs: [configuration, build-previewctl, build-gitpod, infrastructure]
247-
runs-on: [self-hosted]
249+
needs: [ configuration, build-previewctl, build-gitpod, infrastructure ]
250+
runs-on: [ self-hosted ]
248251
concurrency:
249252
group: ${{ github.head_ref || github.ref }}-install
250253
cancel-in-progress: true
@@ -267,8 +270,8 @@ jobs:
267270

268271
monitoring:
269272
name: "Install Monitoring Satellite"
270-
needs: [infrastructure, build-previewctl]
271-
runs-on: [self-hosted]
273+
needs: [ infrastructure, build-previewctl ]
274+
runs-on: [ self-hosted ]
272275
concurrency:
273276
group: ${{ github.head_ref || github.ref }}-monitoring
274277
cancel-in-progress: true

0 commit comments

Comments
 (0)