name: Backup Git repository

on:
  workflow_dispatch:
  push:
    branches:
    - master

jobs:
  BackupBinary:
    runs-on: ubuntu-20.04
    steps:
    - name: Set up Go 1.16
      uses: actions/setup-go@v5.2.0
      with:
        go-version: 1.23
      id: go
    - uses: actions/checkout@v4
    - name: Upgrade upx
      run: |
        # try to fix https://github.com/jenkins-zh/jenkins-cli/issues/493
        wget https://github.com/upx/upx/releases/download/v3.96/upx-3.96-amd64_linux.tar.xz
        tar xvf upx-3.96-amd64_linux.tar.xz
        upx-3.96-amd64_linux/upx -V
        sudo mv upx-3.96-amd64_linux/upx $(which upx)
        upx -V
    - name: Run GoReleaser
      uses: goreleaser/goreleaser-action@v6.1.0
      with:
        version: latest
        args: release --rm-dist --snapshot
  BackupGit:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
    - name: backup
      uses: jenkins-zh/git-backup-actions@v0.0.8
      env:
        GIT_DEPLOY_KEY: ${{ secrets.GIT_DEPLOY_KEY }}
        TARGET_GIT: "git@gitee.com:jenkins-zh/jenkins-cli.git"
  UnitTest:
    name: Test
    runs-on: ubuntu-20.04
    steps:
      - name: Set up Go 1.16
        uses: actions/setup-go@v5.2.0
        with:
          go-version: 1.23
        id: go
      - name: Check out code into the Go module directory
        uses: actions/checkout@v4
      - name: Test
        run: |
          make test
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v5.1.2
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
          files: coverage.out
          flags: unittests
          name: codecov-umbrella
          fail_ci_if_error: true
