@@ -58,24 +58,62 @@ jobs:
5858 matrix :
5959 target : ${{ fromJson(needs.set_targets.outputs.targets_json) }}
6060 steps :
61-
6261 - name : Checkout code
6362 uses : actions/checkout@v4
6463 with :
6564 token : ${{ secrets.GITHUB_TOKEN }}
6665 submodules : recursive
6766 fetch-depth : 0
6867
69- - name : Judge target_triple is win
68+ - name : Judge platform and arch
7069 run : |
7170 if [[ "${{matrix.target}}" == *"windows"* ]]; then
72- echo "is_win=1" >> $GITHUB_ENV
73- wget https://github.com/chainreactors/malefic/releases/latest/download/resources.zip
74- unzip resources.zip -d resources
71+ echo "platform=win" >> $GITHUB_ENV
72+ elif [[ "${{matrix.target}}" == *"linux"* ]]; then
73+ echo "platform=linux" >> $GITHUB_ENV
74+ elif [[ "${{matrix.target}}" == *"darwin"* ]]; then
75+ echo "platform=darwin" >> $GITHUB_ENV
76+ fi
77+
78+ if [[ "${{matrix.target}}" == *"x86_64"* ]]; then
79+ echo "arch=x64" >> $GITHUB_ENV
7580 else
76- echo "is_win=0 " >> $GITHUB_ENV
81+ echo "arch=x86 " >> $GITHUB_ENV
7782 fi
78- wget https://github.com/chainreactors/malefic/releases/latest/download/malefic-mutant-x86_64-unknown-linux-musl
83+
84+ - name : Install Resource
85+ run : |
86+ wget https://github.com/chainreactors/malefic/releases/latest/download/resources.zip
87+ unzip resources.zip -d resources
88+
89+ - name : Generate cache key
90+ id : mutant_cache_key
91+ run : |
92+ HASH=$(find malefic-mutant -name "*.rs" -o -name "Cargo.toml" -o -name "Cargo.lock" | sort | xargs cat | sha256sum | cut -d' ' -f1)
93+ echo "key=mutant-$HASH" >> $GITHUB_OUTPUT
94+
95+ - name : Cache malefic-mutant binary
96+ id : cache_mutant
97+ uses : actions/cache@v4
98+ with :
99+ path : |
100+ target/x86_64-unknown-linux-musl/release/malefic-mutant
101+ key : ${{ steps.mutant_cache_key.outputs.key }}
102+
103+ - name : Pull Docker image
104+ run : |
105+ docker pull ghcr.io/chainreactors/malefic-builder:latest
106+
107+ - name : Build malefic-mutant
108+ if : steps.cache_mutant.outputs.cache-hit != 'true'
109+ run : |
110+ docker run -v $(pwd):/root/src ghcr.io/chainreactors/malefic-builder:latest \
111+ bash -c "cargo build -p malefic-mutant --release --target x86_64-unknown-linux-musl"
112+
113+ - name : Setup malefic-mutant
114+ run : |
115+ mkdir -p target/x86_64-unknown-linux-musl/release/
116+ cp target/x86_64-unknown-linux-musl/release/malefic-mutant malefic-mutant-x86_64-unknown-linux-musl
79117 chmod +x malefic-mutant-x86_64-unknown-linux-musl
80118
81119 - name : Generate config.yaml
@@ -95,48 +133,84 @@ jobs:
95133 echo "SECRET_AUTORUN_YAML_CONTENT=$SECRET_AUTORUN_YAML_CONTENT" >> $GITHUB_ENV
96134 echo "$SECRET_AUTORUN_YAML_CONTENT" | base64 -d > autorun.yaml
97135
136+ - name : Setup Cargo cache directories
137+ run : |
138+ mkdir -p ~/.cargo/registry
139+ mkdir -p ~/.cargo/git
140+ mkdir -p ./cargo-cache/registry
141+ mkdir -p ./cargo-cache/git
142+
143+ - name : Cache Rust dependencies
144+ id : cache_rust
145+ uses : actions/cache@v4
146+ with :
147+ path : |
148+ ./cargo-cache/registry
149+ ./cargo-cache/git
150+ target
151+ key : ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.target }}-${{ github.event.inputs.package }}
152+ restore-keys : |
153+ ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-${{ matrix.target }}-
154+ ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}-
155+ ${{ runner.os }}-cargo-
156+
157+ - name : Verify cache restore
158+ run : |
159+ echo "Cache hit: ${{ steps.cache_rust.outputs.cache-hit }}"
160+ echo "Checking cargo cache directories:"
161+ ls -la ./cargo-cache/ || echo "cargo-cache directory not found"
162+ ls -la ./cargo-cache/registry/ || echo "registry directory not found"
163+ ls -la ./cargo-cache/git/ || echo "git directory not found"
164+
98165 - name : Build(${{ github.event.inputs.package }}, ${{matrix.target}})
99166 if : ${{ github.event.inputs.package == 'beacon' }}
100167 shell : ' script --return --quiet --log-out /dev/null --command "bash -e {0}"'
101168 run : |
102- docker run -v $(pwd):/root/src ghcr.io/chainreactors/malefic-builder:latest \
103- bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate beacon; ./malefic-mutant-x86_64-unknown-linux-musl build malefic --target ${{matrix.target}} "
169+ docker run -v $(pwd):/root/src -v $(pwd)/cargo-cache/registry:/root/cargo/registry -v $(pwd)/cargo-cache/git:/root/cargo/git ghcr.io/chainreactors/malefic-builder:latest \
170+ bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate beacon && ./malefic-mutant-x86_64-unknown-linux-musl build malefic --target ${{matrix.target}}"
104171
105172 - name : Build(${{ github.event.inputs.package }}, ${{matrix.target}})
106173 if : ${{ github.event.inputs.package == 'pulse' }}
107174 shell : ' script --return --quiet --log-out /dev/null --command "bash -e {0}"'
108175 run : |
109- docker run -v $(pwd):/root/src ghcr.io/chainreactors/malefic-builder:latest \
110- bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate pulse x64 win; ./malefic-mutant-x86_64-unknown-linux-musl build pulse; "
176+ docker run -v $(pwd):/root/src -v $(pwd)/cargo-cache/registry:/root/cargo/registry -v $(pwd)/cargo-cache/git:/root/cargo/git ghcr.io/chainreactors/malefic-builder:latest \
177+ bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate pulse -p $platform -a $arch && ./malefic-mutant-x86_64-unknown-linux-musl build pulse --target ${{matrix.target}} "
111178
112179 - name : Build(${{ github.event.inputs.package }}, ${{matrix.target}})
113180 if : ${{ github.event.inputs.package == 'bind' }}
114181 shell : ' script --return --quiet --log-out /dev/null --command "bash -e {0}"'
115182 run : |
116- docker run -v $(pwd):/root/src ghcr.io/chainreactors/malefic-builder:latest \
117- bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate bind; ./malefic-mutant-x86_64-unknown-linux-musl build bind --target ${{matrix.target}} "
183+ docker run -v $(pwd):/root/src -v $(pwd)/cargo-cache/registry:/root/cargo/registry -v $(pwd)/cargo-cache/git:/root/cargo/git ghcr.io/chainreactors/malefic-builder:latest \
184+ bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate bind && ./malefic-mutant-x86_64-unknown-linux-musl build bind --target ${{matrix.target}}"
118185
119186 - name : Build(${{ github.event.inputs.package }}, ${{matrix.target}})
120187 if : ${{ github.event.inputs.package == 'prelude' }}
121188 shell : ' script --return --quiet --log-out /dev/null --command "bash -e {0}"'
122189 run : |
123- docker run -v $(pwd):/root/src ghcr.io/chainreactors/malefic-builder:latest \
124- bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate prelude autorun.yaml;./malefic-mutant-x86_64-unknown-linux-musl build prelude"
190+ docker run -v $(pwd):/root/src -v $(pwd)/cargo-cache/registry:/root/cargo/registry -v $(pwd)/cargo-cache/git:/root/cargo/git ghcr.io/chainreactors/malefic-builder:latest \
191+ bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate prelude autorun.yaml && ./malefic-mutant-x86_64-unknown-linux-musl build prelude --target ${{matrix.target}}"
192+
193+ - name : Build(${{ github.event.inputs.package }},${{matrix.target}})
194+ if : ${{ github.event.inputs.package == '3rd' }}
195+ shell : ' script --return --quiet --log-out /dev/null --command "bash -e {0}"'
196+ run : |
197+ docker run -v $(pwd):/root/src -v $(pwd)/cargo-cache/registry:/root/cargo/registry -v $(pwd)/cargo-cache/git:/root/cargo/git ghcr.io/chainreactors/malefic-builder:latest \
198+ bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate modules -m full && ./malefic-mutant-x86_64-unknown-linux-musl build 3rd -m ${{ github.event.inputs.malefic_modules_features }} --target ${{matrix.target}}"
125199
126200 - name : Build(${{ github.event.inputs.package }},${{matrix.target}})
127201 if : ${{ github.event.inputs.package == 'modules' }}
128202 shell : ' script --return --quiet --log-out /dev/null --command "bash -e {0}"'
129203 run : |
130- docker run -v $(pwd):/root/src ghcr.io/chainreactors/malefic-builder:v0.0.4 \
131- bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate modules ${{ github.event.inputs.malefic_modules_features }}; ./malefic-mutant-x86_64-unknown-linux-musl build modules"
204+ docker run -v $(pwd):/root/src -v $(pwd)/cargo-cache/registry:/root/cargo/registry -v $(pwd)/cargo-cache/git:/root/cargo/git ghcr.io/chainreactors/malefic-builder:latest \
205+ bash -c "./malefic-mutant-x86_64-unknown-linux-musl generate modules -m ${{ github.event.inputs.malefic_modules_features }} && ./malefic-mutant-x86_64-unknown-linux-musl build modules -m ${{ github.event.inputs.malefic_modules_features }} --target ${{matrix.target}} "
132206
133207 - name : Move ${{ github.event.inputs.package }} to output
134208 run : |
135209 mkdir -p output
136210 sudo chmod -R 777 target
137211 sudo chmod -R 777 output
138212 export prefix=./target/${{matrix.target}}/release
139- export suffix=$([ "$is_win " = "1 " ] && echo ".exe" || echo "")
213+ export suffix=$([ "$platform " = "win " ] && echo ".exe" || echo "")
140214 tree ./target
141215 if ${{ github.event.inputs.package == 'beacon' }} || ${{ github.event.inputs.package == 'bind' }}; then \
142216 mv $prefix/malefic$suffix output/malefic-${{ github.event.inputs.package }}$suffix; \
@@ -145,7 +219,9 @@ jobs:
145219 elif ${{ github.event.inputs.package == 'pulse' }}; then \
146220 mv $prefix/malefic-pulse$suffix output/malefic-pulse$suffix;
147221 elif ${{ github.event.inputs.package == 'modules' }}; then \
148- mv $prefix/modules.dll output/modules-${{matrix.target}}.dll; \
222+ mv $prefix/malefic_modules.dll output/malefic_modules-${{matrix.target}}.dll; \
223+ elif ${{ github.event.inputs.package == '3rd' }}; then \
224+ mv $prefix/malefic_3rd.dll output/malefic_3rd-${{matrix.target}}.dll; \
149225 fi
150226
151227 - name : Upload artifact ${{matrix.target}}
@@ -154,4 +230,4 @@ jobs:
154230 with :
155231 name : malefic-${{matrix.target}}-${{ github.run_id }}
156232 path : output/*
157- retention-days : 3 # you can change this value
233+ retention-days : 2 # you can change this value
0 commit comments