|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + |
| 11 | +jobs: |
| 12 | + validate-tag: |
| 13 | + name: Validate Tag |
| 14 | + runs-on: ubuntu-latest |
| 15 | + outputs: |
| 16 | + version: ${{ steps.parse.outputs.version }} |
| 17 | + steps: |
| 18 | + - name: Parse version from tag |
| 19 | + id: parse |
| 20 | + run: | |
| 21 | + TAG="${GITHUB_REF#refs/tags/}" |
| 22 | + # Validate semver format: vMAJOR.MINOR.PATCH with optional pre-release |
| 23 | + if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$ ]]; then |
| 24 | + echo "Error: Tag '$TAG' does not follow semantic versioning (vX.Y.Z)" |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | + VERSION="${TAG#v}" |
| 28 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 29 | + echo "Valid semver tag: $TAG (version: $VERSION)" |
| 30 | +
|
| 31 | + build-release: |
| 32 | + name: Build (${{ matrix.name }}) |
| 33 | + needs: validate-tag |
| 34 | + runs-on: ${{ matrix.os }} |
| 35 | + strategy: |
| 36 | + fail-fast: false |
| 37 | + matrix: |
| 38 | + include: |
| 39 | + - name: Linux |
| 40 | + os: ubuntu-latest |
| 41 | + artifact-name: game-linux |
| 42 | + generator: Ninja |
| 43 | + - name: Windows |
| 44 | + os: windows-latest |
| 45 | + artifact-name: game-windows |
| 46 | + generator: "Visual Studio 17 2022" |
| 47 | + |
| 48 | + steps: |
| 49 | + - name: Checkout repository |
| 50 | + uses: actions/checkout@v4 |
| 51 | + with: |
| 52 | + submodules: recursive |
| 53 | + fetch-depth: 1 |
| 54 | + |
| 55 | + - name: Install dependencies (Linux) |
| 56 | + if: runner.os == 'Linux' |
| 57 | + run: | |
| 58 | + sudo apt-get update |
| 59 | + sudo apt-get install -y \ |
| 60 | + cmake ninja-build \ |
| 61 | + libgl1-mesa-dev \ |
| 62 | + libx11-dev libxrandr-dev libxi-dev \ |
| 63 | + libxinerama-dev libxcursor-dev |
| 64 | +
|
| 65 | + - name: Configure (Release) |
| 66 | + run: > |
| 67 | + cmake -S . -B build |
| 68 | + -G "${{ matrix.generator }}" |
| 69 | + -DCMAKE_BUILD_TYPE=Release |
| 70 | + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 |
| 71 | + -DCMAKE_INSTALL_PREFIX=install |
| 72 | + shell: bash |
| 73 | + |
| 74 | + - name: Build |
| 75 | + run: cmake --build build --config Release -j 4 |
| 76 | + shell: bash |
| 77 | + |
| 78 | + - name: Install |
| 79 | + run: cmake --install build --config Release |
| 80 | + shell: bash |
| 81 | + |
| 82 | + - name: Package artifact |
| 83 | + run: | |
| 84 | + cd install |
| 85 | + tar -czf ../${{ matrix.artifact-name }}-${{ needs.validate-tag.outputs.version }}.tar.gz . |
| 86 | + shell: bash |
| 87 | + |
| 88 | + - name: Upload artifact |
| 89 | + uses: actions/upload-artifact@v4 |
| 90 | + with: |
| 91 | + name: ${{ matrix.artifact-name }} |
| 92 | + path: ${{ matrix.artifact-name }}-${{ needs.validate-tag.outputs.version }}.tar.gz |
| 93 | + retention-days: 90 |
| 94 | + |
| 95 | + create-release: |
| 96 | + name: Create GitHub Release |
| 97 | + needs: [validate-tag, build-release] |
| 98 | + runs-on: ubuntu-latest |
| 99 | + |
| 100 | + steps: |
| 101 | + - name: Checkout repository |
| 102 | + uses: actions/checkout@v4 |
| 103 | + with: |
| 104 | + fetch-depth: 0 |
| 105 | + |
| 106 | + - name: Download all artifacts |
| 107 | + uses: actions/download-artifact@v4 |
| 108 | + with: |
| 109 | + path: release-assets |
| 110 | + merge-multiple: true |
| 111 | + |
| 112 | + - name: Generate changelog from commits |
| 113 | + id: changelog |
| 114 | + run: | |
| 115 | + VERSION="v${{ needs.validate-tag.outputs.version }}" |
| 116 | +
|
| 117 | + # Find previous tag |
| 118 | + PREV_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' | sed -n '2p') |
| 119 | +
|
| 120 | + if [ -n "$PREV_TAG" ]; then |
| 121 | + RANGE="${PREV_TAG}..${VERSION}" |
| 122 | + echo "Generating changelog for $RANGE" |
| 123 | + else |
| 124 | + RANGE="${VERSION}" |
| 125 | + echo "No previous tag found, listing all commits up to ${VERSION}" |
| 126 | + fi |
| 127 | +
|
| 128 | + { |
| 129 | + echo "changelog<<EOF" |
| 130 | + echo "## What's Changed" |
| 131 | + echo "" |
| 132 | +
|
| 133 | + # Group commits by type |
| 134 | + for type_label in "feat:Features" "fix:Bug Fixes" "refactor:Refactors" "perf:Performance" "docs:Documentation" "chore:Chores"; do |
| 135 | + type="${type_label%%:*}" |
| 136 | + label="${type_label#*:}" |
| 137 | +
|
| 138 | + COMMITS=$(git log "$RANGE" --oneline --grep="^${type}" 2>/dev/null || true) |
| 139 | + if [ -n "$COMMITS" ]; then |
| 140 | + echo "### $label" |
| 141 | + echo "$COMMITS" | while read -r line; do |
| 142 | + echo "- $line" |
| 143 | + done |
| 144 | + echo "" |
| 145 | + fi |
| 146 | + done |
| 147 | +
|
| 148 | + echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREV_TAG:-main}...${VERSION}" |
| 149 | + echo "EOF" |
| 150 | + } >> "$GITHUB_OUTPUT" |
| 151 | +
|
| 152 | + - name: Create GitHub Release |
| 153 | + uses: softprops/action-gh-release@v2 |
| 154 | + with: |
| 155 | + tag_name: v${{ needs.validate-tag.outputs.version }} |
| 156 | + name: Release v${{ needs.validate-tag.outputs.version }} |
| 157 | + body: ${{ steps.changelog.outputs.changelog }} |
| 158 | + draft: false |
| 159 | + prerelease: ${{ contains(needs.validate-tag.outputs.version, '-') }} |
| 160 | + files: release-assets/* |
0 commit comments