@@ -3,11 +3,10 @@ name: Build and Upload Artifacts
33on :
44 push :
55 branches : [ main ]
6- tags : [ 'v*' ]
6+ workflow_dispatch :
77
88jobs :
99 build :
10- name : Build Binaries
1110 runs-on : ${{ matrix.os }}
1211 strategy :
1312 matrix :
@@ -26,143 +25,74 @@ jobs:
2625 ext : zip
2726
2827 steps :
29- - name : Checkout Code
28+ - name : Checkout repository
3029 uses : actions/checkout@v4
3130
32- - name : Install Rust Target
31+ - name : Install Rust target
3332 run : rustup target add ${{ matrix.target }}
3433
35- - name : Build Release Binary
34+ - name : Build release binary
3635 run : cargo build --release --target ${{ matrix.target }}
3736
38- - name : Build Package
37+ - name : Package binary and resources
3938 shell : bash
4039 run : |
41- # Set global artifacts directory
42- export ARTIFACTS_DIR="$PWD/release_artifacts"
43- mkdir -p "$ARTIFACTS_DIR"
44-
45- # Build package
40+ mkdir -p release_artifacts/${{ matrix.target }}
4641 cd target/${{ matrix.target }}/release
4742 mkdir -p rfortune-${{ matrix.target }}
4843 cp rfortune rfortune-${{ matrix.target }}/ 2>/dev/null || cp rfortune.exe rfortune-${{ matrix.target }}/
4944 cp $GITHUB_WORKSPACE/README.md $GITHUB_WORKSPACE/CHANGELOG.md $GITHUB_WORKSPACE/LICENSE rfortune-${{ matrix.target }}/
5045
51- - name : Package Windows Binary
52- if : matrix.os == 'windows-latest'
53- shell : pwsh
54- run : |
55- # Path assoluti per evitare problemi
56- $baseDir = $pwd
57- $artifactsDir = "$baseDir/release_artifacts"
58- $targetDir = "$baseDir/target/${{ matrix.target }}/release"
59-
60- # Lavora nella directory di build
61- Push-Location $targetDir
62-
63- try {
64- # Prepara la directory del pacchetto
65- $packageDir = "rfortune-${{ matrix.target }}"
66- $zipPath = "$artifactsDir/rfortune-${{ matrix.target }}.zip"
67- Compress-Archive -Path "$packageDir/*" -DestinationPath $zipPath -CompressionLevel Optimal
68-
69- Write-Host "ZIP creato correttamente in $zipPath"
70- }
71- finally {
72- # Torna sempre alla directory originale
73- Pop-Location
74- }
46+ if [[ "${{ matrix.ext }}" == "zip" ]]; then
47+ cd rfortune-${{ matrix.target }}
48+ zip -r ../rfortune-${{ matrix.target }}.zip .
49+ cd ..
50+ cp rfortune-${{ matrix.target }}.zip $GITHUB_WORKSPACE/release_artifacts/${{ matrix.target }}/
51+ else
52+ tar -czvf rfortune-${{ matrix.target }}.tar.gz rfortune-${{ matrix.target }}
53+ cp rfortune-${{ matrix.target }}.tar.gz $GITHUB_WORKSPACE/release_artifacts/${{ matrix.target }}/
54+ fi
7555
76- - name : Compress with tar on Unix
77- if : matrix.os != 'windows-latest'
56+ - name : Generate SHA256 checksum
7857 shell : bash
7958 run : |
80- export ARTIFACTS_DIR="$PWD/ release_artifacts"
81- cd target/ ${{ matrix.target }}/release
82- tar -czvf $ARTIFACTS_DIR/rfortune-${{ matrix.target }}.tar.gz rfortune-${{ matrix.target }}
59+ cd release_artifacts/${{ matrix.target }}
60+ file=rfortune-${{ matrix. target }}. ${{ matrix.ext }}
61+ sha256sum "$file" > "$file.sha256"
8362
84- - name : Checksum and Sign Package
63+ - name : Sign with GPG
8564 shell : bash
8665 run : |
87- # Setup GPG (once for all operations)
88- echo "${{ secrets. GPG_PRIVATE_KEY }} " | base64 --decode | gpg --batch --import
89- echo "use-agent" >> ~/.gnupg/ gpg.conf
90- echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf
91- echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf
92- gpgconf --kill gpg-agent
93- gpgconf --launch gpg-agent
66+ cd release_artifacts/${{ matrix.target }}
67+ echo "$GPG_PRIVATE_KEY" | base64 --decode | gpg --batch --import
68+ echo "$GPG_PASSPHRASE" | gpg --batch --yes --passphrase-fd 0 --pinentry-mode loopback \
69+ --output "$file.sig" --detach-sign "$file"
70+ env :
71+ GPG_PRIVATE_KEY : ${{ secrets.GPG_PRIVATE_KEY }}
72+ GPG_PASSPHRASE : ${{ secrets.GPG_PASSPHRASE }}
9473
95- export ARTIFACTS_DIR="$PWD/release_artifacts"
96- cd "$ARTIFACTS_DIR"
97-
98- # Generate checksums
99- if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
100- # Windows checksum (PowerShell)
101- pwsh -Command '
102- $file = "rfortune-${{ matrix.target }}.zip"
103- $hash = (Get-FileHash -Algorithm SHA256 $file).Hash.ToLower()
104- "$hash *$file" | Out-File -Encoding utf8 "$file.sha256"
105- '
106- else
107- # Unix checksum
108- sha256sum rfortune-${{ matrix.target }}.* > rfortune-${{ matrix.target }}.sha256 ||
109- shasum -a 256 rfortune-${{ matrix.target }}.* > rfortune-${{ matrix.target }}.sha256
110- fi
111-
112- # Sign artifacts (works for all platforms)
113- for f in rfortune-${{ matrix.target }}.*; do
114- [[ "$f" == *.sig || "$f" == *.sha256 ]] && continue
115- gpg --batch --yes --passphrase "${{ secrets.GPG_PASSPHRASE }}" \
116- --output "$f.sig" --detach-sign "$f"
117- done
74+ upload-artifacts :
75+ name : Upload All Artifacts
76+ runs-on : ubuntu-latest
77+ needs : build
78+ if : ${{ always() }}
79+ steps :
80+ - name : Checkout repository
81+ uses : actions/checkout@v4
11882
119- - name : Clean Previous Artifacts
120- if : matrix.os == 'ubuntu-latest' && matrix.target == 'x86_64-unknown-linux-gnu'
121- uses : actions/github-script@v6
83+ - name : Download all build artifacts from matrix
84+ uses : actions/download-artifact@v4
12285 with :
123- script : |
124- const { data: artifacts } = await github.rest.actions.listWorkflowRunArtifacts({
125- owner: context.repo.owner,
126- repo: context.repo.repo,
127- run_id: context.runId,
128- });
129- for (const artifact of artifacts.artifacts) {
130- if (artifact.name.startsWith('release_artifacts')) {
131- await github.rest.actions.deleteArtifact({
132- owner: context.repo.owner,
133- repo: context.repo.repo,
134- artifact_id: artifact.id,
135- });
136- }
137- }
86+ path : temp_download
13887
139- - name : <Debug>Contenuto della directory release_artifacts</Debug>
88+ - name : Move all platform builds into one folder
14089 shell : bash
14190 run : |
142- echo "Contenuto di release_artifacts/"
143- ls -l release_artifacts
144- echo ""
145- echo "Checksum dei file:"
146- sha256sum release_artifacts/* || shasum -a 256 release_artifacts/*
91+ mkdir release_artifacts
92+ find temp_download -type f -name "rfortune-*" -exec cp {} release_artifacts/ \;
14793
148- - name : Upload Artifacts
94+ - name : Upload combined artifacts for release
14995 uses : actions/upload-artifact@v4
15096 with :
151- name : release_artifacts-${{ matrix.target }}
152- path : release_artifacts/*
153-
154- - name : <Debug>Verifica upload effettivo</Debug>
155- shell : bash
156- run : |
157- echo "Workflow triggering this run:"
158- echo "Workflow name: ${{ github.event.workflow.name }}"
159- echo "Workflow run ID: ${{ github.event.workflow_run.id }}"
160-
161- echo -e "\nContenuto della directory di lavoro"
162- ls -lah .
163-
164- echo -e "\nControllo cartelle Artifact note:"
165- ls -R ${{ github.workspace }}/release_artifacts || echo "Cartella non trovata"
166-
167- echo -e "\nFine debug. Nota: l'upload effettivo degli artifact è gestito da GitHub come archivio separato."
168- echo "I file caricati non vengono spostati o rimossi: puoi ispezionarli ancora nel filesystem locale."
97+ name : release_artifacts
98+ path : release_artifacts
0 commit comments