|
| 1 | +name: CI |
| 2 | + |
| 3 | +# Roda em todo push/PR para verificar compilação. |
| 4 | +# Em push na main com vN.N.N na mensagem: empacota binários e cria nova release. |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + pull_request: |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: ci-${{ github.ref }} |
| 16 | + cancel-in-progress: true |
| 17 | + |
| 18 | +jobs: |
| 19 | + # ──────────────────────────────────────────────────────── |
| 20 | + # 1. Build (todos os targets, todos os pushes/PRs) |
| 21 | + # ──────────────────────────────────────────────────────── |
| 22 | + build: |
| 23 | + name: Build (${{ matrix.target }}) |
| 24 | + runs-on: ${{ matrix.os }} |
| 25 | + |
| 26 | + strategy: |
| 27 | + fail-fast: false |
| 28 | + matrix: |
| 29 | + include: |
| 30 | + - os: windows-latest |
| 31 | + target: x86_64-pc-windows-msvc |
| 32 | + bin: falconasm.exe |
| 33 | + archive: falconasm-windows-x86_64.zip |
| 34 | + |
| 35 | + - os: ubuntu-latest |
| 36 | + target: x86_64-unknown-linux-gnu |
| 37 | + bin: falconasm |
| 38 | + archive: falconasm-linux-x86_64.tar.gz |
| 39 | + |
| 40 | + - os: macos-latest |
| 41 | + target: x86_64-apple-darwin |
| 42 | + bin: falconasm |
| 43 | + archive: falconasm-macos-x86_64.tar.gz |
| 44 | + |
| 45 | + - os: macos-latest |
| 46 | + target: aarch64-apple-darwin |
| 47 | + bin: falconasm |
| 48 | + archive: falconasm-macos-aarch64.tar.gz |
| 49 | + |
| 50 | + steps: |
| 51 | + - uses: actions/checkout@v4 |
| 52 | + |
| 53 | + - uses: dtolnay/rust-toolchain@stable |
| 54 | + with: |
| 55 | + targets: ${{ matrix.target }} |
| 56 | + |
| 57 | + # rfd precisa de GTK3 no Linux (file dialogs) |
| 58 | + - name: Install Linux build tools |
| 59 | + if: runner.os == 'Linux' |
| 60 | + run: sudo apt-get update && sudo apt-get install -y pkg-config libgtk-3-dev |
| 61 | + |
| 62 | + - name: Build |
| 63 | + run: cargo build --release --target ${{ matrix.target }} |
| 64 | + |
| 65 | + # Só empacota quando for push na main |
| 66 | + - name: Package (Windows) |
| 67 | + if: github.ref == 'refs/heads/main' && runner.os == 'Windows' |
| 68 | + shell: pwsh |
| 69 | + run: Compress-Archive "target/${{ matrix.target }}/release/${{ matrix.bin }}" "${{ matrix.archive }}" |
| 70 | + |
| 71 | + - name: Package (Unix) |
| 72 | + if: github.ref == 'refs/heads/main' && runner.os != 'Windows' |
| 73 | + run: | |
| 74 | + tar -czf "${{ matrix.archive }}" \ |
| 75 | + -C "target/${{ matrix.target }}/release" "${{ matrix.bin }}" |
| 76 | +
|
| 77 | + - uses: actions/upload-artifact@v4 |
| 78 | + if: github.ref == 'refs/heads/main' |
| 79 | + with: |
| 80 | + name: dist-${{ matrix.target }} |
| 81 | + path: ${{ matrix.archive }} |
| 82 | + if-no-files-found: error |
| 83 | + |
| 84 | + # ──────────────────────────────────────────────────────── |
| 85 | + # 2. Verifica se a mensagem do commit contém vN.N.N |
| 86 | + # ──────────────────────────────────────────────────────── |
| 87 | + check-release: |
| 88 | + name: Check release trigger |
| 89 | + runs-on: ubuntu-latest |
| 90 | + if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 91 | + outputs: |
| 92 | + should_release: ${{ steps.check.outputs.should_release }} |
| 93 | + steps: |
| 94 | + - name: Check commit message for vN.N.N |
| 95 | + id: check |
| 96 | + run: | |
| 97 | + MSG="${{ github.event.head_commit.message }}" |
| 98 | + if echo "$MSG" | grep -qE 'v[0-9]+\.[0-9]+\.[0-9]+'; then |
| 99 | + echo "should_release=true" >> "$GITHUB_OUTPUT" |
| 100 | + echo "Release trigger found in: $MSG" |
| 101 | + else |
| 102 | + echo "should_release=false" >> "$GITHUB_OUTPUT" |
| 103 | + echo "No vN.N.N found — skipping release" |
| 104 | + fi |
| 105 | +
|
| 106 | + # ──────────────────────────────────────────────────────── |
| 107 | + # 3. Auto-versioned release (só se check-release aprovado) |
| 108 | + # Lê a última tag vX.Y.Z, incrementa Z e cria nova release |
| 109 | + # ──────────────────────────────────────────────────────── |
| 110 | + versioned-release: |
| 111 | + name: Create versioned release |
| 112 | + runs-on: ubuntu-latest |
| 113 | + needs: [build, check-release] |
| 114 | + if: needs.check-release.outputs.should_release == 'true' |
| 115 | + |
| 116 | + steps: |
| 117 | + - uses: actions/checkout@v4 |
| 118 | + with: |
| 119 | + fetch-depth: 0 # precisa de todas as tags |
| 120 | + |
| 121 | + - uses: actions/download-artifact@v4 |
| 122 | + with: |
| 123 | + pattern: dist-* |
| 124 | + path: dist |
| 125 | + merge-multiple: true |
| 126 | + |
| 127 | + - name: SHA256 checksums |
| 128 | + run: cd dist && sha256sum * > SHA256SUMS.txt |
| 129 | + |
| 130 | + - name: Read changelog |
| 131 | + id: changelog |
| 132 | + run: | |
| 133 | + # Extrai a primeira seção do CHANGELOG.md (entre o primeiro ## e o segundo ##) |
| 134 | + NOTES=$(awk '/^## /{if(found){exit} found=1; next} found{print}' CHANGELOG.md) |
| 135 | + { |
| 136 | + echo "notes<<__CHANGELOG_EOF__" |
| 137 | + echo "$NOTES" |
| 138 | + echo "__CHANGELOG_EOF__" |
| 139 | + } >> "$GITHUB_OUTPUT" |
| 140 | +
|
| 141 | + - name: Compute next tag |
| 142 | + id: next_tag |
| 143 | + run: | |
| 144 | + # Pega a última tag vX.Y.Z (ignora "latest" e outras) |
| 145 | + LATEST=$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' \ |
| 146 | + --sort=-version:refname | head -n1) |
| 147 | +
|
| 148 | + if [ -z "$LATEST" ]; then |
| 149 | + NEXT="v0.0.1" |
| 150 | + else |
| 151 | + # Extrai major, minor, patch |
| 152 | + IFS='.' read -r MAJOR MINOR PATCH <<< "${LATEST#v}" |
| 153 | + PATCH=$((PATCH + 1)) |
| 154 | + NEXT="v${MAJOR}.${MINOR}.${PATCH}" |
| 155 | + fi |
| 156 | +
|
| 157 | + echo "tag=$NEXT" >> "$GITHUB_OUTPUT" |
| 158 | + echo "Next release tag: $NEXT" |
| 159 | +
|
| 160 | + - name: Create and push tag |
| 161 | + run: | |
| 162 | + git config user.name "github-actions[bot]" |
| 163 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 164 | + git tag "${{ steps.next_tag.outputs.tag }}" |
| 165 | + git push origin "${{ steps.next_tag.outputs.tag }}" |
| 166 | +
|
| 167 | + - name: Publish release |
| 168 | + uses: softprops/action-gh-release@v2 |
| 169 | + with: |
| 170 | + tag_name: ${{ steps.next_tag.outputs.tag }} |
| 171 | + name: "${{ steps.next_tag.outputs.tag }}" |
| 172 | + prerelease: false |
| 173 | + make_latest: true |
| 174 | + files: dist/* |
| 175 | + generate_release_notes: false |
| 176 | + body: | |
| 177 | + ${{ steps.changelog.outputs.notes }} |
| 178 | +
|
| 179 | + --- |
| 180 | +
|
| 181 | + | Platform | Download | |
| 182 | + |---|---| |
| 183 | + | Windows x64 | `falconasm-windows-x86_64.zip` | |
| 184 | + | Linux x64 | `falconasm-linux-x86_64.tar.gz` | |
| 185 | + | macOS x64 | `falconasm-macos-x86_64.tar.gz` | |
| 186 | + | macOS ARM64 (Apple Silicon) | `falconasm-macos-aarch64.tar.gz` | |
| 187 | +
|
| 188 | + SHA256 de todos os arquivos em `SHA256SUMS.txt`. |
| 189 | +
|
| 190 | + > build [`${{ github.sha }}`](https://github.com/${{ github.repository }}/commit/${{ github.sha }}) |
0 commit comments