-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (138 loc) · 4.7 KB
/
sync-template.yml
File metadata and controls
145 lines (138 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Sync Template to Plugins
on:
push:
branches: [main]
paths:
- Dockerfile
- Makefile
- CODE_OF_CONDUCT.md
- CONTRIBUTING.md
- GOVERNANCE.md
- SECURITY.md
- MAINTAINERS.md
workflow_dispatch:
inputs:
dry_run:
description: Dry run - report drift only, open no PRs
type: boolean
default: false
include_workflows:
description: Also sync .github/workflows/ files (requires SYNC_TOKEN with workflow scope - PAT from github.com/settings/tokens with repo+workflow scopes)
type: boolean
default: false
permissions:
contents: read
jobs:
sync:
name: "Sync ${{ matrix.plugin }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 8
matrix:
plugin:
- analyzer-conventional
- analyzer-default
- condition-generic
- condition-gitea-actions
- condition-github-actions
- condition-gitlab-ci
- generator-changelog-html
- generator-changelog-md
- generator-release-notes
- hook-email
- hook-gitplugin
- hook-jira
- hook-matrix
- hook-slack
- hook-teams
- provider-bitbucket
- provider-git
- provider-gitea
- provider-github
- provider-gitlab
- updater-cargo
- updater-docker
- updater-go
- updater-gradle
- updater-helm
- updater-homebrew
- updater-maven
- updater-npm
- updater-nuget
- updater-python
- updater-terraform
steps:
- name: Check out template
uses: actions/checkout@v6
with:
path: template
- name: Check out plugin
uses: actions/checkout@v6
with:
repository: "SemRels/${{ matrix.plugin }}"
token: ${{ secrets.SYNC_TOKEN }}
path: plugin
- name: Apply template files
env:
PLUGIN: ${{ matrix.plugin }}
INCLUDE_WORKFLOWS: ${{ inputs.include_workflows || 'false' }}
shell: bash
run: |
set -euo pipefail
for f in CODE_OF_CONDUCT.md CONTRIBUTING.md; do
if [ -f "template/$f" ] && [ -f "plugin/$f" ]; then
sed "s/{{PROJECT_NAME}}/$PLUGIN/g; s/{{DEFAULT_BRANCH}}/main/g" "template/$f" > "plugin/$f"
fi
done
for f in Makefile GOVERNANCE.md SECURITY.md MAINTAINERS.md; do
if [ -f "template/$f" ] && [ -f "plugin/$f" ]; then
cp "template/$f" "plugin/$f"
fi
done
if [ -f "template/Dockerfile" ] && [ -f "plugin/Dockerfile" ]; then
sed "s/plugin-template Authors/$PLUGIN Authors/" "template/Dockerfile" > "plugin/Dockerfile"
fi
if [ "$INCLUDE_WORKFLOWS" = "true" ]; then
for wf in ci.yml release.yml security.yml; do
if [ -f "template/.github/workflows/$wf" ] && [ -f "plugin/.github/workflows/$wf" ]; then
cp "template/.github/workflows/$wf" "plugin/.github/workflows/$wf"
fi
done
fi
- name: Create PR if changes exist
env:
GH_TOKEN: ${{ secrets.SYNC_TOKEN }}
DRY_RUN: ${{ inputs.dry_run || 'false' }}
PLUGIN: ${{ matrix.plugin }}
COMMIT_SHA: ${{ github.sha }}
shell: bash
run: |
set -euo pipefail
cd plugin
git config user.name "semrel-sync-bot"
git config user.email "bot@semrel.io"
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/SemRels/${PLUGIN}.git"
if git diff --quiet; then
echo "OK $PLUGIN - no changes needed"
exit 0
fi
CHANGED=$(git diff --name-only | tr '\n' ' ')
echo "DRIFT $PLUGIN - $CHANGED"
if [ "$DRY_RUN" = "true" ]; then
echo "(dry-run - skipping PR)"
exit 0
fi
SHORT_SHA="${COMMIT_SHA:0:7}"
BRANCH="chore/sync-template-$(date +%Y%m%d)"
if git ls-remote --exit-code origin "refs/heads/$BRANCH" > /dev/null 2>&1; then
echo "Branch $BRANCH already exists - skipping"
exit 0
fi
git checkout -b "$BRANCH"
git add -A
git commit -m "chore: sync from plugin-template@${SHORT_SHA} -- $CHANGED"
git push origin "$BRANCH"
TITLE="chore: sync from plugin-template"
BODY="Automated sync from SemRels/plugin-template (${SHORT_SHA}). Updated: $CHANGED"
gh pr create --repo "SemRels/$PLUGIN" --title "$TITLE" --body "$BODY" --base main || echo "PR may already exist"