Publish #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Publish | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| tag: | |
| type: string | |
| description: Tag to publish (e.g. v2.1.2) | |
| required: true | |
| permissions: | |
| contents: read | |
| jobs: | |
| validate-tag: | |
| name: Validate tag | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.event.inputs.tag }} | |
| - name: Verify tag and project version | |
| run: | | |
| TAG="${{ github.event.inputs.tag }}" | |
| if [ -z "$TAG" ]; then | |
| echo "Error: Tag is required." | |
| exit 1 | |
| fi | |
| if ! git rev-parse "$TAG" >/dev/null 2>&1; then | |
| echo "Error: Tag '$TAG' does not exist." | |
| exit 1 | |
| fi | |
| TAG_VERSION="${TAG#v}" | |
| PKG_VERSION=$(grep -E '^project\(ZeroBounce VERSION ' CMakeLists.txt | sed -E 's/.*VERSION ([0-9]+\.[0-9]+\.[0-9]+).*/\1/') | |
| if [ -z "$PKG_VERSION" ]; then | |
| echo "Error: Could not read version from CMakeLists.txt" | |
| exit 1 | |
| fi | |
| if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then | |
| echo "Error: CMakeLists.txt version ($PKG_VERSION) does not match tag ($TAG)." | |
| exit 1 | |
| fi | |
| echo "Publishing tag: $TAG (ZeroBounce C++ SDK $PKG_VERSION)" | |
| test: | |
| name: Test | |
| needs: [validate-tag] | |
| if: ${{ !cancelled() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout tag | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.inputs.tag }} | |
| - name: Install build dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y --no-install-recommends build-essential cmake libssl-dev | |
| - name: Configure and build | |
| run: cmake -S . -B build -G "Unix Makefiles" && cmake --build build | |
| - name: Run tests | |
| run: ctest --test-dir build --output-on-failure | |
| release: | |
| name: Create GitHub Release | |
| needs: [test] | |
| if: ${{ !cancelled() && !failure() }} | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.inputs.tag }} | |
| fetch-depth: 0 | |
| - name: Create release if missing | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| TAG="${{ github.event.inputs.tag }}" | |
| if gh release view "$TAG" --repo "${{ github.repository }}" >/dev/null 2>&1; then | |
| echo "Release $TAG already exists, skipping." | |
| else | |
| gh release create "$TAG" \ | |
| --repo "${{ github.repository }}" \ | |
| --title "$TAG" \ | |
| --generate-notes | |
| fi |