-
-
Notifications
You must be signed in to change notification settings - Fork 1
210 lines (185 loc) · 6.91 KB
/
auto-build-and-publish.yml
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: Automatically build and publish this plugin
on:
push:
branches:
- 'master'
jobs:
build-and-publish-plugin:
runs-on: ubuntu-latest
name: Build and publish plugin
steps:
# Checkout plugin source
- name: Checkout plugin
uses: actions/checkout@v3
with:
path: plugin
submodules: recursive
# Checkout the official plugin repo templates
- name: Checkout official plugin repo templates branch
uses: actions/checkout@v3
with:
repository: Unmanic/unmanic-plugins
ref: template
path: template
# Prepare build environment
- name: Prepare build environment
id: prepare
run: |
# Copy generate repo script to scripts directory
cp -rfv ./template/scripts ./
if [ ! -e ./scripts/generate_repository.py ]; then
echo "Unable to build repo. Could not find generator script."
exit 1
fi
# Create dummy repo config
cat << EOF > config.json
{
"id": "repository.tmp",
"name": "Build Repo",
"icon": ""
}
EOF
# Read plugin id and version from info.json
plugin_id=$(cat plugin/info.json | jq -r .id)
plugin_version=$(cat plugin/info.json | jq -r .version)
echo "plugin_id=${plugin_id}" >> $GITHUB_OUTPUT
echo "plugin_version=${plugin_version}" >> $GITHUB_OUTPUT
# Install plugin into source directory for building
mkdir -p source/
mv -fv plugin source/${plugin_id}
# Setup python environment
- name: Set up Python 3.8
if: success()
uses: actions/setup-python@v4
with:
python-version: 3.8
# Setup node environment
- name: Set up node 16
uses: actions/setup-node@v3
with:
node-version: '16'
# Generate repo
- name: Generate repository from source
if: success()
id: generate_repo
run: |
cat ./source/${{ steps.prepare.outputs.plugin_id }}/info.json
python ./scripts/generate_repository.py
# Upload artifacts
- uses: actions/upload-artifact@v3
with:
name: plugin.${{ steps.prepare.outputs.plugin_id }}-v${{ steps.prepare.outputs.plugin_version }}
path: repo/**/*.zip
# Generate tagged release (should not be updated)
- uses: mukunku/[email protected]
id: check_tag_exists
with:
tag: ${{ steps.prepare.outputs.plugin_version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: test check_tag_exists result
run: echo "RES - '${{ steps.check_tag_exists.outputs.exists }}' -"
- uses: ncipollo/release-action@v1
if: steps.check_tag_exists.outputs.exists == 'false'
with:
name: "Tagged Build: ${{ steps.prepare.outputs.plugin_version }}"
body: "Versioned release"
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: repo/**/*.zip
generateReleaseNotes: true
allowUpdates: false
skipIfReleaseExists: true
tag: ${{ steps.prepare.outputs.plugin_version }}
commit: master
# Generate latest development
- uses: ncipollo/release-action@v1
with:
name: "Development Build"
body: "Latest development release"
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: repo/**/*.zip
generateReleaseNotes: true
allowUpdates: true
removeArtifacts: true
replacesArtifacts: true
tag: latest
commit: master
prerelease: true
generate-pr-in-official-repo:
runs-on: ubuntu-latest
name: Generate PR for official repo
permissions:
contents: write
actions: write
pull-requests: write
steps:
# Configure
- name: Prepare build environment
id: config
run: |
echo "dest_repo=Unmanic/unmanic-plugins" >> $GITHUB_OUTPUT
echo "dest_repo_branch=official" >> $GITHUB_OUTPUT
echo "workflow_run_link=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT
# Checkout the destination plugin repo
- name: Checkout destination plugin repo
uses: actions/checkout@v3
with:
repository: ${{ steps.config.outputs.dest_repo }}
ref: ${{ steps.config.outputs.dest_repo_branch }}
fetch-depth: 0
# Checkout plugin source
- name: Checkout plugin
uses: actions/checkout@v3
with:
path: build/plugin
submodules: recursive
# Prepare build environment
- name: Prepare build environment
id: prepare
run: |
# Read plugin id and version from info.json
plugin_id=$(cat build/plugin/info.json | jq -r .id)
plugin_version=$(cat build/plugin/info.json | jq -r .version)
echo "plugin_id=${plugin_id}" >> $GITHUB_OUTPUT
echo "plugin_version=${plugin_version}" >> $GITHUB_OUTPUT
# Rename plugin directory for building
rm -rf build/plugin.${plugin_id}
mv -fv build/plugin build/plugin.${plugin_id}
# Configure git user for commit messages
- name: Configure git user
uses: fregante/setup-git-user@v1
# Check for plugin updates and create a PR branch with any changes found
- name: Generate PR branch
id: execute
run: |
# # Set the commit user/email
# git config --global user.email "${GITHUB_ACTOR}"
# git config --global user.name "${GITHUB_ACTOR}@users.noreply.github.com"
# Create plugin branch
./.github/workflow_scripts/create_plugin_pr_branch.sh "${{ steps.prepare.outputs.plugin_id }}"
# Parse result
echo "result=$(cat ./result.txt)" >> $GITHUB_OUTPUT
shell: bash
# If a PR branch was created, force push branch to dest repo
- name: Push PR branch
if: steps.execute.outputs.result == 'success'
run: |
git config -l | grep 'http\..*\.extraheader' | cut -d= -f1 | xargs -L1 git config --unset-all
git push -f https://token:${GH_TOKEN}@github.com/${{ steps.config.outputs.dest_repo }}.git "pr-${{ steps.prepare.outputs.plugin_id }}"
# Add a small sleep here before running completing this job
sleep 2
env:
GH_TOKEN: "${{ secrets.GH_TOKEN }}"
# If a PR branch was created, open a PR (if one is not already open)
- name: Generate PR
if: steps.execute.outputs.result == 'success'
run: |
# Execute the 'gh pr create' command and exit quietly without error if the command fails
gh pr create \
--title "[${{ steps.prepare.outputs.plugin_id }}] v${{ steps.prepare.outputs.plugin_version }}" \
--body "PR automatically generated from [plugin source workflow](${{ steps.config.outputs.workflow_run_link }})" \
--base "${{ steps.config.outputs.dest_repo_branch }}" \
--head "pr-${{ steps.prepare.outputs.plugin_id }}" \
--repo "${{ steps.config.outputs.dest_repo }}" || true
env:
GITHUB_TOKEN: "${{ secrets.GH_TOKEN }}"