|
| 1 | +name: Release packages |
| 2 | + |
| 3 | +run-name: Prepare LuaSF draft release for ${{ github.ref_name }} |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + tags: |
| 8 | + - 'v*' |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: release-${{ github.ref }} |
| 15 | + cancel-in-progress: false |
| 16 | + |
| 17 | +jobs: |
| 18 | + build-packages: |
| 19 | + name: Build release packages |
| 20 | + permissions: |
| 21 | + contents: read |
| 22 | + uses: ./.github/workflows/build-packages.yml |
| 23 | + |
| 24 | + create-release: |
| 25 | + name: Create draft release |
| 26 | + needs: build-packages |
| 27 | + runs-on: ubuntu-latest |
| 28 | + timeout-minutes: 15 |
| 29 | + permissions: |
| 30 | + actions: read |
| 31 | + contents: write |
| 32 | + env: |
| 33 | + GH_TOKEN: ${{ github.token }} |
| 34 | + RELEASE_ASSETS_DIR: release-assets |
| 35 | + RELEASE_TAG: ${{ github.ref_name }} |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Download Windows packages |
| 39 | + uses: actions/download-artifact@v8 |
| 40 | + with: |
| 41 | + name: LuaSF-Windows-VS2022-x64 |
| 42 | + path: ${{ env.RELEASE_ASSETS_DIR }} |
| 43 | + |
| 44 | + - name: Download macOS packages |
| 45 | + uses: actions/download-artifact@v8 |
| 46 | + with: |
| 47 | + name: LuaSF-macOS-AppleSilicon-arm64 |
| 48 | + path: ${{ env.RELEASE_ASSETS_DIR }} |
| 49 | + |
| 50 | + - name: Verify release assets |
| 51 | + shell: bash |
| 52 | + run: | |
| 53 | + set -euo pipefail |
| 54 | +
|
| 55 | + expected_files=( |
| 56 | + 'LuaSF-source.zip' |
| 57 | + 'LuaSF-embedded-Windows-x64-MSVC.zip' |
| 58 | + 'LuaSF-extension-Windows-x64-MSVC.zip' |
| 59 | + 'LuaSF-source.tar.gz' |
| 60 | + 'LuaSF-embedded-macOS-ARM64-clang.tar.gz' |
| 61 | + 'LuaSF-extension-macOS-ARM64-clang.tar.gz' |
| 62 | + ) |
| 63 | +
|
| 64 | + for filename in "${expected_files[@]}"; do |
| 65 | + path="$RELEASE_ASSETS_DIR/$filename" |
| 66 | + if [ ! -f "$path" ]; then |
| 67 | + echo "Missing release asset: $path" >&2 |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | + done |
| 71 | +
|
| 72 | + actual_file_count=$(find "$RELEASE_ASSETS_DIR" -mindepth 1 -maxdepth 1 -type f -print | wc -l | tr -d '[:space:]') |
| 73 | + actual_entry_count=$(find "$RELEASE_ASSETS_DIR" -mindepth 1 -maxdepth 1 -print | wc -l | tr -d '[:space:]') |
| 74 | + if [ "$actual_file_count" -ne "${#expected_files[@]}" ] || [ "$actual_entry_count" -ne "${#expected_files[@]}" ]; then |
| 75 | + echo "Expected exactly ${#expected_files[@]} release assets, found $actual_file_count files and $actual_entry_count total entries:" >&2 |
| 76 | + find "$RELEASE_ASSETS_DIR" -mindepth 1 -maxdepth 1 -printf '%f\n' | sort >&2 |
| 77 | + exit 1 |
| 78 | + fi |
| 79 | +
|
| 80 | + - name: Reject an existing release |
| 81 | + shell: bash |
| 82 | + run: | |
| 83 | + set -euo pipefail |
| 84 | +
|
| 85 | + existing_releases=$( |
| 86 | + gh api --paginate --method GET \ |
| 87 | + "repos/$GITHUB_REPOSITORY/releases?per_page=100" \ |
| 88 | + --jq '.[] | [.tag_name, (.id | tostring), (.draft | tostring), .html_url] | @tsv' | |
| 89 | + awk -F '\t' -v tag="$RELEASE_TAG" '$1 == tag { print $2 "\t" $3 "\t" $4 }' |
| 90 | + ) |
| 91 | + if [ -n "$existing_releases" ]; then |
| 92 | + echo "A release already exists for tag '$RELEASE_TAG'; refusing to overwrite it:" >&2 |
| 93 | + printf '%s\n' "$existing_releases" >&2 |
| 94 | + exit 1 |
| 95 | + fi |
| 96 | +
|
| 97 | + - name: Create draft release with six assets |
| 98 | + shell: bash |
| 99 | + run: | |
| 100 | + set -euo pipefail |
| 101 | +
|
| 102 | + gh release create "$RELEASE_TAG" \ |
| 103 | + "$RELEASE_ASSETS_DIR/LuaSF-source.zip" \ |
| 104 | + "$RELEASE_ASSETS_DIR/LuaSF-embedded-Windows-x64-MSVC.zip" \ |
| 105 | + "$RELEASE_ASSETS_DIR/LuaSF-extension-Windows-x64-MSVC.zip" \ |
| 106 | + "$RELEASE_ASSETS_DIR/LuaSF-source.tar.gz" \ |
| 107 | + "$RELEASE_ASSETS_DIR/LuaSF-embedded-macOS-ARM64-clang.tar.gz" \ |
| 108 | + "$RELEASE_ASSETS_DIR/LuaSF-extension-macOS-ARM64-clang.tar.gz" \ |
| 109 | + --repo "$GITHUB_REPOSITORY" \ |
| 110 | + --verify-tag \ |
| 111 | + --draft \ |
| 112 | + --generate-notes |
0 commit comments