|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'Git tag for the release. For example, v1.2.3' |
| 8 | + required: true |
| 9 | + run_id: |
| 10 | + description: 'ID of the CI workflow run that created the release assets' |
| 11 | + type: number |
| 12 | + required: true |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: ${{ github.workflow }}-${{ inputs.version }} |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +permissions: {} |
| 19 | + |
| 20 | +defaults: |
| 21 | + run: |
| 22 | + shell: bash |
| 23 | + |
| 24 | +jobs: |
| 25 | + drafter: |
| 26 | + runs-on: ubuntu-latest |
| 27 | + permissions: |
| 28 | + contents: write |
| 29 | + pull-requests: read |
| 30 | + steps: |
| 31 | + - name: Set DRAFT_RELEASES environment variable |
| 32 | + run: | |
| 33 | + { |
| 34 | + echo 'DRAFT_RELEASES<<EOF' |
| 35 | + gh api --paginate \ |
| 36 | + -H "Accept: application/vnd.github+json" \ |
| 37 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 38 | + "/repos/${REPO}/releases" \ |
| 39 | + --jq 'map(select(.draft)) | .[].id' |
| 40 | + echo EOF |
| 41 | + } >> "$GITHUB_ENV" |
| 42 | + env: |
| 43 | + REPO: ${{ github.repository }} |
| 44 | + GH_TOKEN: ${{ github.token }} |
| 45 | + - run: echo "${DRAFT_RELEASES}" |
| 46 | + |
| 47 | + - name: Delete all draft releases |
| 48 | + if: env.DRAFT_RELEASES != '' |
| 49 | + run: | |
| 50 | + while read -u3 -r draft_release; do |
| 51 | + echo "::group::==> ${draft_release}" |
| 52 | + gh api \ |
| 53 | + --method DELETE \ |
| 54 | + -H "Accept: application/vnd.github+json" \ |
| 55 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 56 | + "/repos/${REPO}/releases/${draft_release}" |
| 57 | + echo "::endgroup::" |
| 58 | + done 3< <(echo "${DRAFT_RELEASES}") |
| 59 | + env: |
| 60 | + REPO: ${{ github.repository }} |
| 61 | + GH_TOKEN: ${{ github.token }} |
| 62 | + |
| 63 | + - uses: release-drafter/release-drafter@v6 |
| 64 | + with: |
| 65 | + version: ${{ inputs.version }} |
| 66 | + tag: ${{ inputs.version }} |
| 67 | + publish: false |
| 68 | + env: |
| 69 | + GITHUB_TOKEN: ${{ github.token }} # Not a typo. |
| 70 | + |
| 71 | + deb: |
| 72 | + needs: drafter |
| 73 | + runs-on: ubuntu-24.04 |
| 74 | + permissions: |
| 75 | + id-token: write |
| 76 | + attestations: write |
| 77 | + contents: write |
| 78 | + actions: read |
| 79 | + steps: |
| 80 | + - name: Set VERSION environment variable |
| 81 | + run: echo VERSION="${TAGISH#v}" >> $GITHUB_ENV |
| 82 | + env: |
| 83 | + TAGISH: ${{ github.ref_type == 'tag' && github.ref_name || format('v0.0.0-{0}+{1}', github.run_number, github.sha) }} |
| 84 | + - run: echo "${VERSION}" |
| 85 | + |
| 86 | + - name: Download nfpm |
| 87 | + run: gh release download --repo goreleaser/nfpm --pattern 'nfpm_*_amd64.deb' --output nfpm.deb |
| 88 | + env: |
| 89 | + GH_TOKEN: ${{ github.token }} |
| 90 | + - name: Install nfpm |
| 91 | + run: sudo dpkg -i nfpm.deb |
| 92 | + |
| 93 | + - uses: actions/checkout@v5 |
| 94 | + with: |
| 95 | + sparse-checkout: | |
| 96 | + nfpm.yaml |
| 97 | + README.md |
| 98 | + LICENSE |
| 99 | + sparse-checkout-cone-mode: false |
| 100 | + - uses: actions/download-artifact@v5 |
| 101 | + with: |
| 102 | + name: binaries |
| 103 | + path: dist |
| 104 | + run-id: ${{ inputs.run_id }} |
| 105 | + github-token: ${{ github.token }} |
| 106 | + |
| 107 | + # TODO! |
| 108 | + - run: ls -la . |
| 109 | + - run: ls -laR dist |
| 110 | + |
| 111 | + - run: mkdir -p deb |
| 112 | + - name: Create deb |
| 113 | + run: | |
| 114 | + for arch in ${ARCHS}; do |
| 115 | + echo "::group::==> ${arch}" |
| 116 | + DIST_DIR="dist/php-matrix_linux_${arch}" \ |
| 117 | + ARCH="${arch}" nfpm package --packager deb --target "deb/php-matrix_linux_${arch}.deb" |
| 118 | + echo "::endgroup::" |
| 119 | + done |
| 120 | + env: |
| 121 | + DIST_DIR: dist |
| 122 | + ARCHS: "arm64 amd64" |
| 123 | + |
| 124 | + # TODO! |
| 125 | + - run: ls -laR deb |
| 126 | + |
| 127 | + - uses: actions/attest-build-provenance@v3 |
| 128 | + with: |
| 129 | + subject-path: deb/*.deb |
| 130 | + |
| 131 | + - name: Upload debs |
| 132 | + run: | |
| 133 | + find deb -type f -name '*.deb' -print0 | |
| 134 | + xargs -0 printf "'%s' " | |
| 135 | + xargs gh release upload --repo "${REPO}" "${TAG}" |
| 136 | + env: |
| 137 | + REPO: ${{ github.repository }} |
| 138 | + TAG: ${{ inputs.version }} |
| 139 | + GH_TOKEN: ${{ github.token }} |
| 140 | + |
| 141 | + tarball: |
| 142 | + needs: drafter |
| 143 | + runs-on: ubuntu-latest |
| 144 | + permissions: |
| 145 | + id-token: write |
| 146 | + attestations: write |
| 147 | + contents: write |
| 148 | + actions: read |
| 149 | + steps: |
| 150 | + - uses: actions/checkout@v5 |
| 151 | + with: |
| 152 | + sparse-checkout: | |
| 153 | + README.md |
| 154 | + LICENSE |
| 155 | + sparse-checkout-cone-mode: false |
| 156 | + ref: ${{ inputs.version }} |
| 157 | + |
| 158 | + - uses: actions/download-artifact@v5 |
| 159 | + with: |
| 160 | + name: binaries |
| 161 | + path: dist |
| 162 | + run-id: ${{ inputs.run_id }} |
| 163 | + github-token: ${{ github.token }} |
| 164 | + |
| 165 | + # TODO! |
| 166 | + - run: ls -la . |
| 167 | + - run: ls -laR dist |
| 168 | + |
| 169 | + - name: Set BIN_DIRS environment variable |
| 170 | + run: | |
| 171 | + echo 'BIN_DIRS<<EOF' >> "$GITHUB_ENV" |
| 172 | + while IFS= read -u3 -r -d '' full_bin_path; do |
| 173 | + echo "::group::==> ${full_bin_path}" |
| 174 | + full_dir=$(dirname "${full_bin_path}") |
| 175 | + dir=$(basename -a "${full_dir}") |
| 176 | + echo "${dir}" >> "$GITHUB_ENV" |
| 177 | + echo "::endgroup::" |
| 178 | + done 3< <(find dist -maxdepth 2 -mindepth 2 -type f -name 'php-matrix' -print0) |
| 179 | + echo EOF >> "$GITHUB_ENV" |
| 180 | + - run: echo "${BIN_DIRS}" |
| 181 | + |
| 182 | + - run: mkdir -p tarball |
| 183 | + - name: Create tarballs |
| 184 | + run: | |
| 185 | + while read -u3 -r bin_dir; do |
| 186 | + echo "::group::==> ${bin_dir}" |
| 187 | + cp README.md LICENSE "bin/${bin_dir}/" |
| 188 | + chmod +x "bin/${bin_dir}/php-matrix" && \ |
| 189 | + tar -C "bin/${bin_dir}" -cvf - php-matrix README.md LICENSE | \ |
| 190 | + gzip --best - > "tarball/${bin_dir}.tar.gz" |
| 191 | + echo "::endgroup::" |
| 192 | + done 3< <(echo "${BIN_DIRS}") |
| 193 | +
|
| 194 | + # TODO! |
| 195 | + - run: ls -la . |
| 196 | + - run: ls -laR tarball |
| 197 | + |
| 198 | + - name: Validate tarballs |
| 199 | + run: | |
| 200 | + while read -u3 -r bin_dir; do |
| 201 | + echo "::group::==> ${bin_dir}" |
| 202 | + tar -tvf "tarball/${bin_dir}.tar.gz" |
| 203 | + echo "::endgroup::" |
| 204 | + done 3< <(echo "${BIN_DIRS}") |
| 205 | +
|
| 206 | + - uses: actions/attest-build-provenance@v3 |
| 207 | + with: |
| 208 | + subject-path: tarball/*.tar.gz |
| 209 | + |
| 210 | + - name: Upload tarballs |
| 211 | + run: | |
| 212 | + find tarball -type f -name '*.tar.gz' -print0 | |
| 213 | + xargs -0 printf "'%s' " | |
| 214 | + xargs gh release upload --repo "${REPO}" "${TAG}" |
| 215 | + env: |
| 216 | + REPO: ${{ github.repository }} |
| 217 | + TAG: ${{ inputs.version }} |
| 218 | + GH_TOKEN: ${{ github.token }} |
| 219 | + |
| 220 | + publish: |
| 221 | + needs: |
| 222 | + - drafter |
| 223 | + - deb |
| 224 | + - tarball |
| 225 | + runs-on: ubuntu-latest |
| 226 | + steps: |
| 227 | + - name: Create GitHub App Token |
| 228 | + uses: actions/create-github-app-token@v2 |
| 229 | + id: app-token |
| 230 | + with: |
| 231 | + app-id: ${{ vars.TASTENDRUCK_APP_ID }} |
| 232 | + private-key: ${{ secrets.TASTENDRUCK_PRIVATE_KEY }} |
| 233 | + |
| 234 | + - name: Publish the release |
| 235 | + run: | |
| 236 | + gh release edit --repo "${REPO}" "${TAG}" --draft=false |
| 237 | + env: |
| 238 | + REPO: ${{ github.repository }} |
| 239 | + TAG: ${{ inputs.version }} |
| 240 | + GH_TOKEN: ${{ steps.app-token.outputs.token }} |
0 commit comments