Publish APT Repository (Signed) #31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish APT Repository (Signed) | |
| on: | |
| workflow_run: | |
| workflows: ["Build and Release .deb"] | |
| types: [completed] | |
| workflow_dispatch: | |
| jobs: | |
| publish-apt: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Capturar artifact deb-package (workflow_run only) | |
| if: ${{ github.event_name == 'workflow_run' }} | |
| uses: actions/github-script@v7 | |
| id: get-artifacts | |
| with: | |
| script: | | |
| const run_id = context.payload.workflow_run.id; | |
| const { data } = await github.rest.actions.listWorkflowRunArtifacts({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| run_id | |
| }); | |
| const deb = data.artifacts.find(a => a.name === "deb-package"); | |
| if (!deb) { | |
| core.setFailed("Artifact 'deb-package' não encontrado neste run."); | |
| return; | |
| } | |
| core.setOutput("artifact_id", deb.id.toString()); | |
| - name: Baixar artifact via API (workflow_run only) | |
| if: ${{ github.event_name == 'workflow_run' }} | |
| env: | |
| GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
| run: | | |
| set -e | |
| ART_ID="${{ steps.get-artifacts.outputs.artifact_id }}" | |
| mkdir -p _artifact && cd _artifact | |
| curl -L -H "Authorization: Bearer $GH_TOKEN" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -o artifact.zip \ | |
| "https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/artifacts/${ART_ID}/zip" | |
| unzip artifact.zip -d deb-package | |
| cd .. | |
| - name: Download .deb do release Ubuntu-linux (manual only) | |
| if: ${{ github.event_name == 'workflow_dispatch' }} | |
| uses: robinraju/release-downloader@v1 | |
| with: | |
| repository: ${{ github.repository }} | |
| tag: Ubuntu-linux | |
| fileName: "*.deb" | |
| out-file-path: repo/pool/main/ | |
| - name: Organizar .deb em repo/pool/main | |
| run: | | |
| mkdir -p repo/pool/main | |
| shopt -s globstar nullglob | |
| for f in _artifact/deb-package/**/*.deb repo/pool/main/**/*.deb; do | |
| [ -f "$f" ] && cp -v "$f" repo/pool/main/ || true | |
| done | |
| ls -l repo/pool/main || true | |
| - name: Install tools | |
| run: sudo apt-get update && sudo apt-get install -y dpkg-dev gnupg apt-utils | |
| - name: Import GPG key | |
| env: | |
| GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }} | |
| run: | | |
| set -e | |
| mkdir -p ~/.gnupg | |
| chmod 700 ~/.gnupg | |
| echo "$GPG_PRIVATE_KEY" | gpg --batch --import | |
| printf "use-agent\npinentry-mode loopback\n" > ~/.gnupg/gpg.conf | |
| printf "allow-loopback-pinentry\n" > ~/.gnupg/gpg-agent.conf | |
| echo RELOADAGENT | gpg-connect-agent | |
| gpg --list-secret-keys | |
| - name: Generate signed Release files | |
| env: | |
| GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }} | |
| run: | | |
| set -e | |
| mkdir -p repo/dists/stable/main/binary-amd64 | |
| cd repo | |
| apt-ftparchive packages pool > dists/stable/main/binary-amd64/Packages | |
| gzip -kf dists/stable/main/binary-amd64/Packages | |
| cat > apt-ftparchive.conf << 'EOF' | |
| APT::FTPArchive::Release { | |
| Origin "DeveloperStartSpringboot"; | |
| Label "DeveloperStartSpringboot"; | |
| Suite "stable"; | |
| Codename "stable"; | |
| Architectures "amd64"; | |
| Components "main"; | |
| Description "DeveloperStartSpringboot APT repository"; | |
| } | |
| EOF | |
| apt-ftparchive -c apt-ftparchive.conf release dists/stable > dists/stable/Release | |
| gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \ | |
| -abs -o dists/stable/Release.gpg dists/stable/Release | |
| gpg --batch --yes --pinentry-mode loopback --passphrase "$GPG_PASSPHRASE" \ | |
| --clearsign -o dists/stable/InRelease dists/stable/Release | |
| cd .. | |
| - name: Export public key | |
| run: | | |
| mkdir -p repo | |
| gpg --armor --export > repo/public.key | |
| - name: Deploy to gh-pages | |
| uses: peaceiris/actions-gh-pages@v4 | |
| with: | |
| github_token: ${{ secrets.GH_TOKEN }} | |
| publish_branch: gh-pages | |
| publish_dir: repo | |
| keep_files: true | |
| commit_message: "Update signed APT repo (trigger: ${{ github.event_name }})" |