# oohelperd builds and publishes oohelperd for Linux
name: oohelperd
on:
  push:
    branches:
      - "release/**"
      - "oohelperd-staging"

jobs:
  build_amd64:
    runs-on: "ubuntu-20.04"
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-go@v1
        with:
          go-version: "1.17.3"

      - name: build oohelperd binary
        run: GOOS=linux GOARCH=amd64 go build -v ./internal/cmd/oohelperd

      - run: find . -type f -name oohelperd

      - name: install deps
        run: |
          sudo apt-get -q update
          sudo apt-get install -yq --no-install-recommends curl devscripts \
            dpkg-dev debhelper git python3 python3-requests python3-gnupg s3cmd

      - name: update the debian changelog
        run: |
          version="$(go run ./internal/cmd/printversion)~$GITHUB_RUN_NUMBER"
          cd ./internal/cmd/oohelperd
          dch -v "$version" "New version ${version}"

      - name: build deb package
        run: |
          cd ./internal/cmd/oohelperd
          dpkg-buildpackage -us -uc -b

      - name: upload package
        if: github.ref == 'refs/heads/oohelperd-staging'
        run: |
          curl -fsSLO https://raw.githubusercontent.com/ooni/sysadmin/master/tools/debops-ci
          chmod +x debops-ci
          find . -name '*.deb'
          ./debops-ci --show-commands upload --bucket-name ooni-internal-deb --arch "amd64" internal/cmd/*.deb
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          DEB_GPG_KEY: ${{ secrets.DEB_GPG_KEY }}
