From 5053fc6aee9b65cef2e85d7dddf53ca68b1e713a Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Thu, 29 Dec 2022 16:08:32 +0800 Subject: [PATCH] chore(CI): migrate to GitHub Actions --- .github/FUNDING.yml | 13 +++ .github/dependabot.yml | 10 +++ .github/workflows/binary.yml | 24 ++++++ .github/workflows/codeql.yml | 54 ++++++++++++ .github/workflows/docker.yml | 138 +++++++++++++++++++++++++++++++ .github/workflows/goreleaser.yml | 35 ++++++++ .github/workflows/lint.yml | 53 ++++++++++++ 7 files changed, 327 insertions(+) create mode 100644 .github/FUNDING.yml create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/binary.yml create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/goreleaser.yml create mode 100644 .github/workflows/lint.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..df9ae63 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,13 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry +custom: ['https://www.paypal.me/appleboy46'] diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..632e8eb --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly + - package-ecosystem: gomod + directory: / + schedule: + interval: weekly diff --git a/.github/workflows/binary.yml b/.github/workflows/binary.yml new file mode 100644 index 0000000..8a04145 --- /dev/null +++ b/.github/workflows/binary.yml @@ -0,0 +1,24 @@ +name: Release Binary + +on: + push: + branches: + - master + tags: + - 'v*' + +jobs: + build: + runs-on: ubuntu-latest + container: techknowlogick/xgo:go-1.19.x + steps: + + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + # - name: Release binary + # run: | + # ls -al + # make release diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..2d9bcdd --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,54 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ master ] + schedule: + - cron: '41 23 * * 6' + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'go' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://git.io/codeql-language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..cafb86c --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,138 @@ +name: Docker Image + +on: + push: + branches: + - master + tags: + - 'v*' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Setup go + uses: actions/setup-go@v3 + with: + go-version: '^1' + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Build binary + run : | + make build_linux_amd64 + make build_linux_arm64 + make build_linux_arm + + - name: Check binary + run : | + ./release/linux/amd64/drone-scp --help + + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - + name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - + name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - + name: Docker meta for linux amd64 + id: meta-linux-amd64 + uses: docker/metadata-action@v4 + with: + flavor: | + latest=false + suffix=linux-amd64 + images: | + appleboy/drone-scp + ghcr.io/appleboy/drone-scp + tags: | + type=raw,value=,enable={{is_default_branch}} + type=raw,value=latest,suffix=,enable={{is_default_branch}} + type=semver,event=tag,pattern={{version}},suffix=-linux-amd64 + type=semver,event=tag,pattern={{major}}.{{minor}},suffix=-linux-amd64 + type=semver,event=tag,pattern={{major}},suffix=-linux-amd64 + + - + name: Build and push linux amd64 + uses: docker/build-push-action@v3 + with: + context: . + file: docker/Dockerfile.linux.amd64 + platforms: linux/amd64 + push: true + tags: ${{ steps.meta-linux-amd64.outputs.tags }} + labels: ${{ steps.meta-linux-amd64.outputs.labels }} + + - + name: Docker meta for linux arm64 + id: meta-linux-arm64 + uses: docker/metadata-action@v4 + with: + flavor: | + latest=false + suffix=linux-arm64 + images: | + appleboy/drone-scp + ghcr.io/appleboy/drone-scp + tags: | + type=raw,value=,enable={{is_default_branch}} + type=semver,event=tag,pattern={{version}},suffix=-linux-arm64 + type=semver,event=tag,pattern={{major}}.{{minor}},suffix=-linux-arm64 + type=semver,event=tag,pattern={{major}},suffix=-linux-arm64 + + - + name: Build and push linux arm64 + uses: docker/build-push-action@v3 + with: + context: . + file: docker/Dockerfile.linux.arm64 + platforms: linux/arm64 + push: true + tags: ${{ steps.meta-linux-arm64.outputs.tags }} + labels: ${{ steps.meta-linux-arm64.outputs.labels }} + + - + name: Docker meta for linux arm + id: meta-linux-arm + uses: docker/metadata-action@v4 + with: + flavor: | + latest=false + suffix=linux-arm + images: | + appleboy/drone-scp + ghcr.io/appleboy/drone-scp + tags: | + type=raw,value=,enable={{is_default_branch}} + type=semver,event=tag,pattern={{version}},suffix=-linux-arm + type=semver,event=tag,pattern={{major}}.{{minor}},suffix=-linux-arm + type=semver,event=tag,pattern={{major}},suffix=-linux-arm + + - + name: Build and push linux arm + uses: docker/build-push-action@v3 + with: + context: . + file: docker/Dockerfile.linux.arm + platforms: linux/arm + push: true + tags: ${{ steps.meta-linux-arm.outputs.tags }} + labels: ${{ steps.meta-linux-arm.outputs.labels }} diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 0000000..d6be714 --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,35 @@ +name: Goreleaser + +on: + push: + tags: + - '*' + +permissions: + contents: write + +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - + name: Setup go + uses: actions/setup-go@v3 + with: + go-version: '^1' + + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v4 + with: + # either 'goreleaser' (default) or 'goreleaser-pro' + distribution: goreleaser + version: latest + args: release --rm-dist + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..4c507df --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,53 @@ +name: Lint and Testing + +on: + push: + pull_request: + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - name: Setup go + uses: actions/setup-go@v3 + with: + go-version: '^1' + - name: Checkout repository + uses: actions/checkout@v3 + - name: Setup golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: latest + args: --verbose + + - uses: hadolint/hadolint-action@v3.0.0 + name: hadolint for Dockerfile.linux.amd64 + with: + dockerfile: docker/Dockerfile.linux.amd64 + - uses: hadolint/hadolint-action@v3.0.0 + name: hadolint for Dockerfile.linux.arm64 + with: + dockerfile: docker/Dockerfile.linux.arm64 + - uses: hadolint/hadolint-action@v3.0.0 + name: hadolint for Dockerfile.linux.arm + with: + dockerfile: docker/Dockerfile.linux.arm + + testing: + runs-on: ubuntu-latest + container: golang:1.19-alpine + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: setup sshd server + run: | + apk add git make curl perl bash build-base zlib-dev ucl-dev + make ssh-server + + - name: testing + run: | + make test + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3