|
| 1 | +name: bundle-full-source |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + tag_name: |
| 7 | + description: 'Release tag to bundle' |
| 8 | + required: true |
| 9 | + default: 'v0.0.1' |
| 10 | + resource_asset_name: |
| 11 | + description: 'Existing release asset name to merge into resources/' |
| 12 | + required: true |
| 13 | + default: 'resources.zip' |
| 14 | + merge_strategy: |
| 15 | + description: 'How to handle duplicate files under resources/' |
| 16 | + required: true |
| 17 | + type: choice |
| 18 | + default: 'fail' |
| 19 | + options: |
| 20 | + - fail |
| 21 | + - overwrite |
| 22 | + bundle_asset_name: |
| 23 | + description: 'Optional override for the uploaded bundle asset name' |
| 24 | + required: false |
| 25 | + default: '' |
| 26 | + |
| 27 | +permissions: |
| 28 | + contents: write |
| 29 | + |
| 30 | +jobs: |
| 31 | + bundle-full-source: |
| 32 | + runs-on: ubuntu-22.04 |
| 33 | + env: |
| 34 | + TAG_NAME: ${{ inputs.tag_name }} |
| 35 | + RESOURCE_ASSET_NAME: ${{ inputs.resource_asset_name }} |
| 36 | + MERGE_STRATEGY: ${{ inputs.merge_strategy }} |
| 37 | + steps: |
| 38 | + - name: Checkout tagged source |
| 39 | + uses: actions/checkout@v4 |
| 40 | + with: |
| 41 | + ref: ${{ inputs.tag_name }} |
| 42 | + submodules: recursive |
| 43 | + fetch-depth: 0 |
| 44 | + |
| 45 | + - name: Install Rust toolchain for cargo vendor |
| 46 | + uses: dtolnay/rust-toolchain@nightly |
| 47 | + |
| 48 | + - name: Resolve bundle names |
| 49 | + id: bundle_names |
| 50 | + shell: bash |
| 51 | + run: | |
| 52 | + version="${TAG_NAME}" |
| 53 | + root_dir="malefic-community-${version}-full-source" |
| 54 | + bundle_name="${{ inputs.bundle_asset_name }}" |
| 55 | +
|
| 56 | + if [[ -z "$bundle_name" ]]; then |
| 57 | + bundle_name="${root_dir}.zip" |
| 58 | + fi |
| 59 | +
|
| 60 | + echo "ROOT_DIR=$root_dir" >> "$GITHUB_OUTPUT" |
| 61 | + echo "BUNDLE_NAME=$bundle_name" >> "$GITHUB_OUTPUT" |
| 62 | +
|
| 63 | + - name: Download resource archive from release |
| 64 | + env: |
| 65 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 66 | + shell: bash |
| 67 | + run: | |
| 68 | + mkdir -p .release-assets |
| 69 | + gh release download "$TAG_NAME" \ |
| 70 | + --repo "${GITHUB_REPOSITORY}" \ |
| 71 | + --pattern "$RESOURCE_ASSET_NAME" \ |
| 72 | + --dir .release-assets \ |
| 73 | + --clobber |
| 74 | +
|
| 75 | + test -f ".release-assets/$RESOURCE_ASSET_NAME" |
| 76 | +
|
| 77 | + - name: Merge resource archive into resources/ |
| 78 | + shell: bash |
| 79 | + run: | |
| 80 | + mkdir -p resources .bundle-work/resources-unpacked |
| 81 | + unzip -q ".release-assets/$RESOURCE_ASSET_NAME" -d .bundle-work/resources-unpacked |
| 82 | +
|
| 83 | + shopt -s dotglob nullglob |
| 84 | + extracted=(.bundle-work/resources-unpacked/*) |
| 85 | + merge_root=".bundle-work/resources-unpacked" |
| 86 | +
|
| 87 | + if [[ ${#extracted[@]} -eq 1 && -d "${extracted[0]}" && "$(basename "${extracted[0]}")" == "resources" ]]; then |
| 88 | + merge_root="${extracted[0]}" |
| 89 | + fi |
| 90 | +
|
| 91 | + if [[ "$MERGE_STRATEGY" == "fail" ]]; then |
| 92 | + conflicts=() |
| 93 | +
|
| 94 | + while IFS= read -r -d '' file; do |
| 95 | + rel_path="${file#${merge_root}/}" |
| 96 | + if [[ -e "resources/${rel_path}" ]]; then |
| 97 | + conflicts+=("${rel_path}") |
| 98 | + fi |
| 99 | + done < <(find "$merge_root" -type f -print0) |
| 100 | +
|
| 101 | + if [[ ${#conflicts[@]} -gt 0 ]]; then |
| 102 | + echo "::error::Detected conflicting resource files:" |
| 103 | + printf ' - %s\n' "${conflicts[@]:0:20}" |
| 104 | + if [[ ${#conflicts[@]} -gt 20 ]]; then |
| 105 | + echo " - ... and $(( ${#conflicts[@]} - 20 )) more" |
| 106 | + fi |
| 107 | + exit 1 |
| 108 | + fi |
| 109 | + fi |
| 110 | +
|
| 111 | + rsync -a "${merge_root}/" resources/ |
| 112 | +
|
| 113 | + - name: Vendor Rust dependencies |
| 114 | + shell: bash |
| 115 | + run: | |
| 116 | + mkdir -p .bundle-work .cargo |
| 117 | +
|
| 118 | + cargo vendor --locked --versioned-dirs vendor \ |
| 119 | + --sync examples/ffi/rust/Cargo.toml \ |
| 120 | + --sync examples/starship/Cargo.toml \ |
| 121 | + --sync lib/rage/Cargo.toml \ |
| 122 | + --sync malefic-3rd-template/Cargo.toml \ |
| 123 | + --sync malefic-proxydll/Cargo.toml \ |
| 124 | + --sync malefic-starship/Cargo.toml \ |
| 125 | + > .bundle-work/cargo-vendor-config.toml |
| 126 | +
|
| 127 | + if [[ -f .cargo/config.toml ]]; then |
| 128 | + cp .cargo/config.toml .bundle-work/base-config.toml |
| 129 | + printf '\n' >> .bundle-work/base-config.toml |
| 130 | + cat .bundle-work/base-config.toml .bundle-work/cargo-vendor-config.toml > .cargo/config.toml |
| 131 | + else |
| 132 | + cp .bundle-work/cargo-vendor-config.toml .cargo/config.toml |
| 133 | + fi |
| 134 | +
|
| 135 | + - name: Build complete source archive |
| 136 | + shell: bash |
| 137 | + run: | |
| 138 | + root_dir="${{ steps.bundle_names.outputs.ROOT_DIR }}" |
| 139 | + bundle_name="${{ steps.bundle_names.outputs.BUNDLE_NAME }}" |
| 140 | + stage_dir="dist/${root_dir}" |
| 141 | +
|
| 142 | + mkdir -p "$stage_dir" |
| 143 | + rsync -a ./ "$stage_dir"/ \ |
| 144 | + --exclude '.git' \ |
| 145 | + --exclude '.bundle-work' \ |
| 146 | + --exclude '.release-assets' \ |
| 147 | + --exclude 'dist' \ |
| 148 | + --exclude 'target' \ |
| 149 | + --exclude '.DS_Store' |
| 150 | +
|
| 151 | + ( |
| 152 | + cd dist |
| 153 | + zip -qry -y "$bundle_name" "$root_dir" |
| 154 | + ) |
| 155 | +
|
| 156 | + - name: Upload complete source archive |
| 157 | + env: |
| 158 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 159 | + shell: bash |
| 160 | + run: | |
| 161 | + bundle_name="${{ steps.bundle_names.outputs.BUNDLE_NAME }}" |
| 162 | + gh release upload "$TAG_NAME" \ |
| 163 | + "dist/${bundle_name}" \ |
| 164 | + --repo "${GITHUB_REPOSITORY}" \ |
| 165 | + --clobber |
0 commit comments