|
| 1 | +name: Release Metadata |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + force: |
| 7 | + description: 'Force regeneration of all metadata' |
| 8 | + type: boolean |
| 9 | + default: false |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: release-metadata |
| 13 | + cancel-in-progress: false |
| 14 | + |
| 15 | +jobs: |
| 16 | + generate: |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + include: |
| 21 | + - arch: x86_64-Linux |
| 22 | + runner: ubuntu-latest |
| 23 | + - arch: aarch64-Linux |
| 24 | + runner: ubuntu-24.04-arm |
| 25 | + runs-on: ${{ matrix.runner }} |
| 26 | + permissions: |
| 27 | + contents: read |
| 28 | + packages: read |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Install tools |
| 34 | + run: | |
| 35 | + ARCH="$(uname -m)-linux" |
| 36 | + sudo apt-get update |
| 37 | + sudo apt-get install -y zstd xz-utils jq |
| 38 | +
|
| 39 | + # Download sbuild-meta |
| 40 | + curl -fsSL "https://github.com/pkgforge/sbuilder/releases/download/latest/sbuild-meta-${ARCH}" \ |
| 41 | + -o /usr/local/bin/sbuild-meta || { |
| 42 | + echo "::error::Failed to download sbuild-meta" |
| 43 | + exit 1 |
| 44 | + } |
| 45 | + chmod +x /usr/local/bin/sbuild-meta |
| 46 | +
|
| 47 | + sbuild-meta --version |
| 48 | +
|
| 49 | + - name: Generate bincache metadata |
| 50 | + env: |
| 51 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 52 | + run: | |
| 53 | + mkdir -p /tmp/output |
| 54 | +
|
| 55 | + # Note: For test repo, the packages are pushed to bincache-test |
| 56 | + # sbuild-meta will look for ghcr.io/pkgforge/bincache-test/<pkg> |
| 57 | + sbuild-meta generate \ |
| 58 | + --arch "${{ matrix.arch }}" \ |
| 59 | + --recipes ./binaries \ |
| 60 | + --output /tmp/output \ |
| 61 | + --cache-type bincache \ |
| 62 | + --parallel 4 \ |
| 63 | + --github-token "$GITHUB_TOKEN" || { |
| 64 | + echo "::warning::bincache metadata generation failed or no packages found" |
| 65 | + } |
| 66 | +
|
| 67 | + # Rename to include cache type |
| 68 | + if [ -f "/tmp/output/bincache/${{ matrix.arch }}.json" ]; then |
| 69 | + mv "/tmp/output/bincache/${{ matrix.arch }}.json" "/tmp/output/bincache-${{ matrix.arch }}.json" |
| 70 | + echo "::notice::bincache metadata generated" |
| 71 | + jq 'length' "/tmp/output/bincache-${{ matrix.arch }}.json" |
| 72 | + else |
| 73 | + echo "::warning::No bincache metadata generated" |
| 74 | + fi |
| 75 | +
|
| 76 | + - name: Generate pkgcache metadata |
| 77 | + env: |
| 78 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 79 | + run: | |
| 80 | + sbuild-meta generate \ |
| 81 | + --arch "${{ matrix.arch }}" \ |
| 82 | + --recipes ./packages \ |
| 83 | + --output /tmp/output \ |
| 84 | + --cache-type pkgcache \ |
| 85 | + --parallel 4 \ |
| 86 | + --github-token "$GITHUB_TOKEN" || { |
| 87 | + echo "::warning::pkgcache metadata generation failed or no packages found" |
| 88 | + } |
| 89 | +
|
| 90 | + # Rename to include cache type |
| 91 | + if [ -f "/tmp/output/pkgcache/${{ matrix.arch }}.json" ]; then |
| 92 | + mv "/tmp/output/pkgcache/${{ matrix.arch }}.json" "/tmp/output/pkgcache-${{ matrix.arch }}.json" |
| 93 | + echo "::notice::pkgcache metadata generated" |
| 94 | + jq 'length' "/tmp/output/pkgcache-${{ matrix.arch }}.json" |
| 95 | + else |
| 96 | + echo "::warning::No pkgcache metadata generated" |
| 97 | + fi |
| 98 | +
|
| 99 | + - name: List outputs |
| 100 | + run: | |
| 101 | + echo "=== Generated files ===" |
| 102 | + ls -lah /tmp/output/ || echo "No files" |
| 103 | +
|
| 104 | + for f in /tmp/output/*.json; do |
| 105 | + if [ -f "$f" ]; then |
| 106 | + echo "=== $(basename $f) ===" |
| 107 | + jq '.[0:2]' "$f" 2>/dev/null || cat "$f" |
| 108 | + fi |
| 109 | + done |
| 110 | +
|
| 111 | + - name: Compress outputs |
| 112 | + run: | |
| 113 | + cd /tmp/output |
| 114 | +
|
| 115 | + for file in *.json; do |
| 116 | + if [ -f "$file" ]; then |
| 117 | + # Compress with zstd |
| 118 | + zstd -19 "$file" -o "${file}.zstd" |
| 119 | + fi |
| 120 | + done |
| 121 | +
|
| 122 | + ls -lah |
| 123 | +
|
| 124 | + - name: Upload artifacts |
| 125 | + uses: actions/upload-artifact@v4 |
| 126 | + with: |
| 127 | + name: metadata-${{ matrix.arch }} |
| 128 | + path: | |
| 129 | + /tmp/output/*.json |
| 130 | + /tmp/output/*.json.zstd |
| 131 | + retention-days: 7 |
| 132 | + |
| 133 | + release: |
| 134 | + needs: generate |
| 135 | + runs-on: ubuntu-latest |
| 136 | + permissions: |
| 137 | + contents: write |
| 138 | + steps: |
| 139 | + - name: Download all artifacts |
| 140 | + uses: actions/download-artifact@v4 |
| 141 | + with: |
| 142 | + path: /tmp/artifacts |
| 143 | + merge-multiple: true |
| 144 | + |
| 145 | + - name: List artifacts |
| 146 | + run: | |
| 147 | + echo "=== Downloaded artifacts ===" |
| 148 | + ls -lah /tmp/artifacts/ || echo "No artifacts" |
| 149 | +
|
| 150 | + - name: Create release |
| 151 | + env: |
| 152 | + GH_TOKEN: ${{ github.token }} |
| 153 | + run: | |
| 154 | + VERSION="v$(date -u '+%Y%m%d.%H%M%S')" |
| 155 | +
|
| 156 | + # Check if we have any files |
| 157 | + if [ -z "$(ls -A /tmp/artifacts/ 2>/dev/null)" ]; then |
| 158 | + echo "::warning::No artifacts to release" |
| 159 | + exit 0 |
| 160 | + fi |
| 161 | +
|
| 162 | + # Generate release notes |
| 163 | + cat > /tmp/release_notes.md << EOF |
| 164 | + ## Metadata Release |
| 165 | +
|
| 166 | + **Generated**: $(date -u '+%Y-%m-%d %H:%M:%S UTC') |
| 167 | +
|
| 168 | + ### Contents |
| 169 | +
|
| 170 | + | File | Size | |
| 171 | + |------|------| |
| 172 | + EOF |
| 173 | +
|
| 174 | + for f in /tmp/artifacts/*; do |
| 175 | + if [ -f "$f" ]; then |
| 176 | + size=$(ls -lh "$f" | awk '{print $5}') |
| 177 | + echo "| $(basename $f) | $size |" >> /tmp/release_notes.md |
| 178 | + fi |
| 179 | + done |
| 180 | +
|
| 181 | + cat >> /tmp/release_notes.md << EOF |
| 182 | +
|
| 183 | + --- |
| 184 | + *This release was generated automatically from test repository.* |
| 185 | + EOF |
| 186 | +
|
| 187 | + # Create the release |
| 188 | + gh release create "$VERSION" \ |
| 189 | + --title "Metadata $VERSION" \ |
| 190 | + --notes-file /tmp/release_notes.md \ |
| 191 | + --repo "${{ github.repository }}" \ |
| 192 | + /tmp/artifacts/* || { |
| 193 | + echo "::error::Failed to create release" |
| 194 | + exit 1 |
| 195 | + } |
| 196 | +
|
| 197 | + echo "::notice::Created release $VERSION" |
0 commit comments