-
Notifications
You must be signed in to change notification settings - Fork 90
163 lines (140 loc) · 5.15 KB
/
bundle-full-source.yml
File metadata and controls
163 lines (140 loc) · 5.15 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: bundle-full-source
on:
workflow_dispatch:
inputs:
tag_name:
description: 'Release tag to bundle'
required: true
default: 'v0.0.1'
resource_asset_name:
description: 'Existing release asset name to merge into resources/'
required: true
default: 'resources.zip'
merge_strategy:
description: 'How to handle duplicate files under resources/'
required: true
type: choice
default: 'fail'
options:
- fail
- overwrite
bundle_asset_name:
description: 'Optional override for the uploaded bundle asset name'
required: false
default: ''
permissions:
contents: write
jobs:
bundle-full-source:
runs-on: ubuntu-22.04
env:
TAG_NAME: ${{ inputs.tag_name }}
RESOURCE_ASSET_NAME: ${{ inputs.resource_asset_name }}
MERGE_STRATEGY: ${{ inputs.merge_strategy }}
steps:
- name: Checkout tagged source
uses: actions/checkout@v4
with:
ref: ${{ inputs.tag_name }}
submodules: recursive
fetch-depth: 0
- name: Install Rust toolchain for cargo vendor
uses: dtolnay/rust-toolchain@nightly
- name: Resolve bundle names
id: bundle_names
shell: bash
run: |
version="${TAG_NAME}"
root_dir="malefic"
source_dir="${root_dir}/source_code"
default_bundle_name="malefic-community-${version}-full-source.zip"
bundle_name="${{ inputs.bundle_asset_name }}"
if [[ -z "$bundle_name" ]]; then
bundle_name="${default_bundle_name}"
fi
echo "ROOT_DIR=$root_dir" >> "$GITHUB_OUTPUT"
echo "SOURCE_DIR=$source_dir" >> "$GITHUB_OUTPUT"
echo "BUNDLE_NAME=$bundle_name" >> "$GITHUB_OUTPUT"
- name: Download resource archive from release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
mkdir -p .release-assets
gh release download "$TAG_NAME" \
--repo "${GITHUB_REPOSITORY}" \
--pattern "$RESOURCE_ASSET_NAME" \
--dir .release-assets \
--clobber
test -f ".release-assets/$RESOURCE_ASSET_NAME"
- name: Merge resource archive into resources/
shell: bash
run: |
mkdir -p resources .bundle-work/resources-unpacked
unzip -q ".release-assets/$RESOURCE_ASSET_NAME" -d .bundle-work/resources-unpacked
shopt -s dotglob nullglob
extracted=(.bundle-work/resources-unpacked/*)
merge_root=".bundle-work/resources-unpacked"
if [[ ${#extracted[@]} -eq 1 && -d "${extracted[0]}" && "$(basename "${extracted[0]}")" == "resources" ]]; then
merge_root="${extracted[0]}"
fi
if [[ "$MERGE_STRATEGY" == "fail" ]]; then
conflicts=()
while IFS= read -r -d '' file; do
rel_path="${file#${merge_root}/}"
if [[ -e "resources/${rel_path}" ]]; then
conflicts+=("${rel_path}")
fi
done < <(find "$merge_root" -type f -print0)
if [[ ${#conflicts[@]} -gt 0 ]]; then
echo "::error::Detected conflicting resource files:"
printf ' - %s\n' "${conflicts[@]:0:20}"
if [[ ${#conflicts[@]} -gt 20 ]]; then
echo " - ... and $(( ${#conflicts[@]} - 20 )) more"
fi
exit 1
fi
fi
rsync -a "${merge_root}/" resources/
- name: Vendor Rust dependencies
shell: bash
run: |
mkdir -p .bundle-work .cargo
cargo vendor --locked --versioned-dirs vendor \
> .bundle-work/cargo-vendor-config.toml
if [[ -f .cargo/config.toml ]]; then
cp .cargo/config.toml .bundle-work/base-config.toml
printf '\n' >> .bundle-work/base-config.toml
cat .bundle-work/base-config.toml .bundle-work/cargo-vendor-config.toml > .cargo/config.toml
else
cp .bundle-work/cargo-vendor-config.toml .cargo/config.toml
fi
- name: Build complete source archive
shell: bash
run: |
root_dir="${{ steps.bundle_names.outputs.ROOT_DIR }}"
source_dir="${{ steps.bundle_names.outputs.SOURCE_DIR }}"
bundle_name="${{ steps.bundle_names.outputs.BUNDLE_NAME }}"
stage_dir="dist/${source_dir}"
mkdir -p "$stage_dir"
rsync -a ./ "$stage_dir"/ \
--exclude '.git' \
--exclude '.bundle-work' \
--exclude '.release-assets' \
--exclude 'dist' \
--exclude 'target' \
--exclude '.DS_Store'
(
cd dist
zip -qry -y "$bundle_name" "$root_dir"
)
- name: Upload complete source archive
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
bundle_name="${{ steps.bundle_names.outputs.BUNDLE_NAME }}"
gh release upload "$TAG_NAME" \
"dist/${bundle_name}" \
--repo "${GITHUB_REPOSITORY}" \
--clobber