# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
#
# SPDX-License-Identifier: curl

name: dist

'on':
  push:
    branches:
      - master
      - '*/ci'
  pull_request:
    branches:
      - master

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
  cancel-in-progress: true

permissions: {}

env:
  MAKEFLAGS: -j 5

jobs:
  maketgz-and-verify-in-tree:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
        with:
          persist-credentials: false

      - name: 'remove preinstalled curl libcurl4{-doc}'
        run: sudo apt-get -o Dpkg::Use-Pty=0 purge curl libcurl4 libcurl4-doc

      - name: 'autoreconf'
        run: autoreconf -fi

      - name: 'configure'
        run: ./configure --without-ssl --without-libpsl

      - name: 'make'
        run: make V=1

      - name: 'maketgz'
        run: SOURCE_DATE_EPOCH=1711526400 ./scripts/maketgz 99.98.97

      - uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
        with:
          name: 'release-tgz'
          path: 'curl-99.98.97.tar.gz'
          retention-days: 1

      - name: 'verify in-tree configure build including install'
        run: |
          echo "::stop-commands::$(uuidgen)"
          tar xvf curl-99.98.97.tar.gz
          pushd curl-99.98.97
          ./configure --prefix=$HOME/temp --without-ssl --without-libpsl
          make
          make test-ci
          make install
          popd
          # basic check of the installed files
          bash scripts/installcheck.sh $HOME/temp
          rm -rf curl-99.98.97

  verify-out-of-tree-docs:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    needs: maketgz-and-verify-in-tree
    steps:
      - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
        with:
          name: 'release-tgz'

      - name: 'verify out-of-tree configure build including docs'
        run: |
          echo "::stop-commands::$(uuidgen)"
          tar xvf curl-99.98.97.tar.gz
          touch curl-99.98.97/docs/{cmdline-opts,libcurl}/Makefile.inc
          mkdir build
          pushd build
          ../curl-99.98.97/configure --without-ssl --without-libpsl
          make
          make test-ci
          popd
          rm -rf build
          rm -rf curl-99.98.97

  verify-out-of-tree-autotools-debug:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    needs: maketgz-and-verify-in-tree
    steps:
      - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
        with:
          name: 'release-tgz'

      - name: 'verify out-of-tree autotools debug build'
        run: |
          echo "::stop-commands::$(uuidgen)"
          tar xvf curl-99.98.97.tar.gz
          pushd curl-99.98.97
          mkdir build
          pushd build
          ../configure --without-ssl --enable-debug "--prefix=${PWD}/pkg" --without-libpsl
          make
          make test-ci
          make install

  verify-out-of-tree-cmake:
    runs-on: ubuntu-latest
    timeout-minutes: 15
    needs: maketgz-and-verify-in-tree
    steps:
      - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
        with:
          name: 'release-tgz'

      - name: 'verify out-of-tree cmake build'
        run: |
          echo "::stop-commands::$(uuidgen)"
          tar xvf curl-99.98.97.tar.gz
          pushd curl-99.98.97
          cmake -B build -DCURL_WERROR=ON -DCURL_USE_LIBPSL=OFF
          make -C build

  missing-files:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    needs: maketgz-and-verify-in-tree
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
        with:
          persist-credentials: false

      - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
        with:
          name: 'release-tgz'

      - name: 'detect files missing from release tarball'
        run: .github/scripts/distfiles.sh curl-99.98.97.tar.gz

  reproducible-releases:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
        with:
          persist-credentials: false

      - name: 'remove preinstalled curl libcurl4{-doc}'
        run: sudo apt-get -o Dpkg::Use-Pty=0 purge curl libcurl4 libcurl4-doc

      - name: 'generate release tarballs'
        run: ./scripts/dmaketgz 9.10.11

      - name: 'verify release tarballs'
        run: |
          mkdir _verify
          mv curl-9.10.11.tar.gz _verify
          cd _verify
          ../scripts/verify-release curl-9.10.11.tar.gz

  cmake-integration:
    name: 'cmake-integration-on-${{ matrix.image }}'
    runs-on: ${{ matrix.image }}
    timeout-minutes: 10
    env:
      CC: clang
      CMAKE_GENERATOR: Ninja
    strategy:
      fail-fast: false
      matrix:
        image: [ubuntu-latest, macos-latest]
    steps:
      - name: 'install prereqs'
        run: |
          if [[ '${{ matrix.image }}' = *'ubuntu'* ]]; then
            sudo apt-get -o Dpkg::Use-Pty=0 install ninja-build libpsl-dev libssl-dev
          else
            brew install ninja libpsl openssl
          fi

      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
        with:
          persist-credentials: false
      - name: 'via FetchContent'
        run: ./tests/cmake/test.sh FetchContent
      - name: 'via add_subdirectory'
        run: ./tests/cmake/test.sh add_subdirectory
      - name: 'via find_package'
        run: ./tests/cmake/test.sh find_package
