Skip to content

Commit 94e071e

Browse files
committed
ci: Harden some and ignore others that are blocked from forks
Signed-off-by: Joas Schilling <[email protected]>
1 parent 519d77d commit 94e071e

File tree

5 files changed

+96
-14
lines changed

5 files changed

+96
-14
lines changed

.github/workflows/block-merge-eol.yml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,22 @@ jobs:
2727

2828
steps:
2929
- name: Set server major version environment
30-
run: |
31-
# retrieve version number from branch reference
32-
server_major=$(echo "${{ github.base_ref }}" | sed -En 's/stable//p')
33-
echo "server_major=$server_major" >> $GITHUB_ENV
34-
echo "current_month=$(date +%Y-%m)" >> $GITHUB_ENV
35-
36-
- name: Checking if ${{ env.server_major }} is EOL
30+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
31+
with:
32+
github-token: ${{secrets.GITHUB_TOKEN}}
33+
script: |
34+
const regex = /^stable(\d+)$/
35+
const baseRef = context.payload.pull_request.base.ref
36+
const match = baseRef.match(regex)
37+
if (match) {
38+
console.log('Setting server_major to ' + match[1]);
39+
core.exportVariable('server_major', match[1]);
40+
console.log('Setting current_month to ' + (new Date()).toISOString().substr(0, 7));
41+
core.exportVariable('current_month', (new Date()).toISOString().substr(0, 7));
42+
}
43+
44+
- name: Checking if server ${{ env.server_major }} is EOL
45+
if: ${{ env.server_major != '' }}
3746
run: |
3847
curl -s https://raw.githubusercontent.com/nextcloud-releases/updater_server/production/config/major_versions.json \
3948
| jq '.["${{ env.server_major }}"]["eol"] // "9999-99" | . >= "${{ env.current_month }}"' \

.github/workflows/block-merge-freeze.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,30 @@ jobs:
2828
runs-on: ubuntu-latest-low
2929

3030
steps:
31-
- name: Download version.php from ${{ github.base_ref }}
32-
run: curl 'https://raw.githubusercontent.com/nextcloud/server/${{ github.base_ref }}/version.php' --output version.php
31+
- name: Register server reference to fallback to master branch
32+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
33+
with:
34+
github-token: ${{secrets.GITHUB_TOKEN}}
35+
script: |
36+
const baseRef = context.payload.pull_request.base.ref
37+
if (baseRef === 'main' || baseRef === 'master') {
38+
core.exportVariable('server_ref', 'master');
39+
console.log('Setting server_ref to master');
40+
} else {
41+
const regex = /^stable(\d+)$/
42+
const match = baseRef.match(regex)
43+
if (match) {
44+
core.exportVariable('server_ref', match[0]);
45+
console.log('Setting server_ref to ' + match[0]);
46+
} else {
47+
console.log('Not based on master/main/stable*, so skipping freeze check');
48+
}
49+
}
50+
51+
- name: Download version.php from ${{ env.server_ref }}
52+
if: ${{ env.server_ref != '' }}
53+
run: curl 'https://raw.githubusercontent.com/nextcloud/server/${{ env.server_ref }}/version.php' --output version.php
3354

3455
- name: Run check
56+
if: ${{ env.server_ref != '' }}
3557
run: cat version.php | grep 'OC_VersionString' | grep -i -v 'RC'

.github/workflows/block-outdated-3rdparty.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,36 @@ jobs:
4040
run: |
4141
echo "commit=$(git submodule status | grep ' 3rdparty' | egrep -o '[a-f0-9]{40}')" >> "$GITHUB_OUTPUT"
4242
43+
- name: Register server reference to fallback to master branch
44+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
45+
with:
46+
github-token: ${{secrets.GITHUB_TOKEN}}
47+
script: |
48+
const baseRef = context.payload.pull_request.base.ref
49+
if (baseRef === 'main' || baseRef === 'master') {
50+
core.exportVariable('server_ref', 'master');
51+
console.log('Setting server_ref to master');
52+
} else {
53+
const regex = /^stable(\d+)$/
54+
const match = baseRef.match(regex)
55+
if (match) {
56+
core.exportVariable('server_ref', match[0]);
57+
console.log('Setting server_ref to ' + match[0]);
58+
} else {
59+
console.log('Not based on master/main/stable*, so skipping freeze check');
60+
}
61+
}
62+
4363
- name: Last 3rdparty commit on target branch
4464
id: target
4565
run: |
46-
echo "commit=$(git ls-remote https://github.com/nextcloud/3rdparty refs/heads/${{ github.base_ref }} | awk '{ print $1}')" >> "$GITHUB_OUTPUT"
66+
echo "commit=$(git ls-remote https://github.com/nextcloud/3rdparty refs/heads/${{ env.server_ref }} | awk '{ print $1}')" >> "$GITHUB_OUTPUT"
4767
4868
- name: Compare if 3rdparty commits are different
4969
run: |
5070
echo '3rdparty/ seems to not point to the last commit of the dedicated branch:'
5171
echo 'Branch has: ${{ steps.actual.outputs.commit }}'
52-
echo '${{ github.base_ref }} has: ${{ steps.target.outputs.commit }}'
72+
echo '${{ env.server_ref }} has: ${{ steps.target.outputs.commit }}'
5373
5474
- name: Fail if 3rdparty commits are different
5575
if: ${{ steps.changes.outputs.src != 'false' && steps.actual.outputs.commit != steps.target.outputs.commit }}

.github/workflows/command-pull-3rdparty.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,49 @@ jobs:
4545
token: ${{ secrets.COMMAND_BOT_PAT }}
4646
ref: ${{ steps.comment-branch.outputs.head_ref }}
4747

48+
- name: Register server reference to fallback to master branch
49+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
50+
with:
51+
github-token: ${{secrets.GITHUB_TOKEN}}
52+
script: |
53+
const baseRef = context.payload.pull_request.base.ref
54+
if (baseRef === 'main' || baseRef === 'master') {
55+
core.exportVariable('server_ref', 'master');
56+
console.log('Setting server_ref to master');
57+
} else {
58+
const regex = /^stable(\d+)$/
59+
const match = baseRef.match(regex)
60+
if (match) {
61+
core.exportVariable('server_ref', match[0]);
62+
console.log('Setting server_ref to ' + match[0]);
63+
} else {
64+
console.log('Not based on master/main/stable*, so skipping freeze check');
65+
}
66+
}
67+
4868
- name: Setup git
4969
run: |
5070
git config --local user.email '[email protected]'
5171
git config --local user.name 'nextcloud-command'
5272
73+
- name: Add reaction on failure
74+
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v3.0.1
75+
if: ${{ env.server_ref == '' }}
76+
with:
77+
token: ${{ secrets.COMMAND_BOT_PAT }}
78+
repository: ${{ github.event.repository.full_name }}
79+
comment-id: ${{ github.event.comment.id }}
80+
reactions: '-1'
81+
5382
- name: Pull 3rdparty
54-
run: git submodule foreach 'if [ "$sm_path" == "3rdparty" ]; then git pull origin '"'"'${{ github.event.issue.pull_request.base.ref }}'"'"'; fi'
83+
if: ${{ env.server_ref != '' }}
84+
run: git submodule foreach 'if [ "$sm_path" == "3rdparty" ]; then git pull origin '"'"'${{ env.server_ref }}'"'"'; fi'
5585

5686
- name: Commit and push changes
87+
if: ${{ env.server_ref != '' }}
5788
run: |
5889
git add 3rdparty
59-
git commit -s -m 'Update submodule 3rdparty to latest ${{ github.event.issue.pull_request.base.ref }}'
90+
git commit -s -m 'Update submodule 3rdparty to latest ${{ env.server_ref }}'
6091
git push
6192
6293
- name: Add reaction on failure

.github/workflows/performance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
output: before.json
7474
profiler-branch: master
7575

76-
- name: Apply PR
76+
- name: Apply PR # zizmor: ignore[template-injection]
7777
run: |
7878
git remote add pr '${{ github.event.pull_request.head.repo.clone_url }}'
7979
git fetch pr '${{ github.event.pull_request.head.ref }}'

0 commit comments

Comments
 (0)