Skip to content

Commit d218284

Browse files
authored
Merge pull request #218 from TechnologyEnhancedLearning/ci-dependabot-setup
Ci dependabot setup
2 parents a852b58 + c9ede7b commit d218284

7 files changed

Lines changed: 128 additions & 6 deletions

.github/workflows/automerge-dependabot-prs-into-collected-branch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This script seperate major and minor but we do merge them into the same branch.
22
# Having two steps allows us to easily turn off major changes in future and then script them to their own branch and pipeline.
3-
name: Auto-merge Dependabot PRs
3+
name: Auto-merge Dependabot PRs into collected branch
44
on:
55
pull_request:
66
types: [opened, synchronize]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Collected Dependabot Promotion From Staging To Master
2+
on:
3+
schedule:
4+
# we want the opposite weeks to staging so we get a week where it occurs in manual testing
5+
- cron: '0 9 8-14 * 1' # Second Monday of month
6+
- cron: '0 9 22-28 * 1' # Fourth Monday of month
7+
workflow_dispatch:
8+
9+
jobs:
10+
promote-to-master:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Check for changes
22+
id: changes
23+
run: |
24+
git fetch origin Automatic_collected_dependabot_staging:Automatic_collected_dependabot_staging
25+
git fetch origin master:master # or main/master - whatever your prod branch is
26+
27+
if git diff --quiet master Automatic_collected_dependabot_staging; then
28+
echo "has_changes=false" >> $GITHUB_OUTPUT
29+
else
30+
echo "has_changes=true" >> $GITHUB_OUTPUT
31+
fi
32+
33+
- name: Create PR to master
34+
if: steps.changes.outputs.has_changes == 'true'
35+
run: |
36+
if gh pr list --head Automatic_collected_dependabot_staging --base master --json number --jq '.[0].number' | grep -q .; then
37+
echo "PR already exists, skipping creation"
38+
else
39+
gh pr create \
40+
--base master \
41+
--head Automatic_collected_dependabot_staging \
42+
--title "Fortnightly dependabot collected master promotion - $(date +%Y-%m-%d)" \
43+
--body "Automated weekly promotion from staging to master after testing period" \
44+
--auto-merge \
45+
--merge
46+
fi
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Dependabot Collected Promotion To Staging
2+
# this logic will require branch ruleset checks of running the dev pipeline
3+
on:
4+
schedule:
5+
# Promotion from staging to release should be a week apart so alternating weeks (also live updates dangerous)
6+
- cron: '0 9 1-7 * 1' # First Monday of month
7+
- cron: '0 9 15-21 * 1' # Third Monday of month
8+
workflow_dispatch: # Allow manual trigger
9+
10+
jobs:
11+
promote-to-automatic-collected-dependabot-staging:
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Check for changes
23+
id: changes
24+
run: |
25+
git fetch origin Automatic_version_update_dependabot:Automatic_version_update_dependabot
26+
git fetch origin Automatic_collected_dependabot_staging:Automatic_collected_dependabot_staging
27+
28+
if git diff --quiet Automatic_collected_dependabot_staging Automatic_version_update_dependabot; then
29+
echo "has_changes=false" >> $GITHUB_OUTPUT
30+
else
31+
echo "has_changes=true" >> $GITHUB_OUTPUT
32+
fi
33+
34+
- name: Create PR to Automatic_collected_dependabot_staging
35+
if: steps.changes.outputs.has_changes == 'true'
36+
run: |
37+
gh pr create \
38+
--base Automatic_collected_dependabot_staging \
39+
--head Automatic_version_update_dependabot \
40+
--title "Fortnightly dependabot collected to staging - $(date +%Y-%m-%d)" \
41+
--body "Automated Fortnightly promotion of dependency updates from dependabot" \
42+
--auto-merge \
43+
--merge
44+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/dev.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,35 @@ jobs:
9292
- name: Run dev semantic version (None Blocking)
9393
id: detect_semantic_version
9494
run: |
95+
echo "error catch run of semver first to get any error detail on config issues"
96+
set +e
97+
SEMVER_OUTPUT_RAW_ERROR_CHECK=$(npx semantic-release --dry-run 2> /tmp/semantic-release-errors.log)
98+
STATUS_ERROR_CHECK=$?
99+
100+
# Now you can check the status and log the error messages if an error occurred
101+
if [ $STATUS_ERROR_CHECK -ne 0 ]; then
102+
echo "❌ Semantic release failed with exit code $STATUS_ERROR_CHECK."
103+
echo "❌ Error output:"
104+
cat /tmp/semantic-release-errors.log
105+
else
106+
echo "✅ Semantic Ouput success : $SEMVER_OUTPUT_RAW_ERROR_CHECK "
107+
echo "✅ Error on success : $STATUS_ERROR_CHECK"
108+
fi
109+
110+
set -e
111+
95112
96113
echo "running semantic-release"
97-
SEMVER_OUTPUT_RAW=$(npx semantic-release --dry-run 2>&1)
98-
STATUS=$?
114+
semver_output_raw=$(npx semantic-release --dry-run 2>&1)
115+
status=$?
116+
117+
# Now you can check the status and log the error messages if an error occurred
118+
if [ $STATUS -ne 0 ]; then
119+
echo "Semantic release failed with exit code $STATUS."
120+
echo "Error output:"
121+
cat /tmp/semantic-release-errors.log
122+
fi
123+
99124
echo "status = $STATUS"
100125
echo "$SEMVER_OUTPUT_RAW"
101126
@@ -361,5 +386,4 @@ jobs:
361386
-H "Authorization: Bearer $TEL_GIT_PACKAGES_TOKEN" \
362387
-H "X-GitHub-Api-Version: 2022-11-28" \
363388
https://api.github.com/repos/$repo_owner/$repo_name/dispatches \
364-
-d "{\"event_type\": \"$event_type\", \"client_payload\": {\"artifact_url\": \"$artifact_url\"}}"
365-
389+
-d "{\"event_type\": \"$event_type\", \"client_payload\": {\"artifact_url\": \"$artifact_url\"}}"

.github/workflows/workflow-readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ The individual steps also automatically pass so can see if any error at the end
8484
- dependabot duplicates tokens using dependabot secrets including write so can run checks
8585
- autoverging is being tried for major and minor
8686
- branch checks must pass for merge on automated_version
87-
87+
- checks required but overrideable for all workflows
8888
## Versioning
8989
Via semantic release and recorded as a generate c# file used by a blazor component
9090

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,4 @@ TELBlazor.Components.ShowCase.E2ETests.WasmServerHost/Logs/*
236236

237237
# Generated version info files
238238
TELBlazor.Components/TELBlazorPackageVersion/VersionInfo*.cs
239+
/.github/workflows/test.yml

.releaserc.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
{
77
"name": "Automatic_version_update_dependabot"
88
},
9+
{
10+
"name": "Automatic_collected_dependabot_staging",
11+
"prerelease": "dependabot-staging"
12+
},
913
{
1014
"name": "feat-*",
1115
"prerelease": true

0 commit comments

Comments
 (0)