From 79be50933e34c0543e8ee398ce3bad3e50d03472 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 14 Sep 2022 08:13:38 +0800 Subject: [PATCH] chore: update github actions --- .../build-and-push-release-image.yml | 44 +++++++++++ .github/workflows/codeql.yml | 70 ++++++++++++++++++ .github/workflows/tests.yml | 73 +++++++++++++++++++ .vscode/settings.json | 4 + 4 files changed, 191 insertions(+) create mode 100644 .github/workflows/build-and-push-release-image.yml create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/tests.yml create mode 100644 .vscode/settings.json diff --git a/.github/workflows/build-and-push-release-image.yml b/.github/workflows/build-and-push-release-image.yml new file mode 100644 index 0000000..282a91a --- /dev/null +++ b/.github/workflows/build-and-push-release-image.yml @@ -0,0 +1,44 @@ +name: build-and-push-release-image + +on: + push: + branches: + # Run on pushing branches like `release/1.0.0` + - "release/v*.*.*" + +jobs: + build-and-push-release-image: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Extract build args + # Extract version from branch name + # Example: branch name `release/v1.0.0` sets up env.VERSION=1.0.0 + run: | + echo "VERSION=${GITHUB_REF_NAME#release/v}" >> $GITHUB_ENV + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: neosmemo + password: ${{ secrets.DOCKER_NEOSMEMO_TOKEN }} + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + with: + install: true + + - name: Build and Push + id: docker_build + uses: docker/build-push-action@v3 + with: + context: ./ + file: ./Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: neosmemo/memos:latest, neosmemo/memos:${{ env.VERSION }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..d743f33 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,70 @@ +# 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: [main] + pull_request: + # The branches below must be a subset of the branches above + branches: [main] + schedule: + - cron: "27 12 * * 0" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: ["go", "javascript"] + # 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@v2 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + 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 + + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl + + # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language + + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..9a5227c --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,73 @@ +name: Test + +on: + push: + branches: + - main + - "release/v*.*.*" + pull_request: + branches: [main] + +jobs: + go-static-checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.18 + check-latest: true + cache: true + - name: Verify go.mod is tidy + run: | + go mod tidy + git diff --exit-code + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + args: -v + skip-cache: true + + eslint-checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: "16" + cache: yarn + cache-dependency-path: "web/yarn.lock" + - run: yarn + working-directory: web + - name: Run eslint check + run: yarn lint + working-directory: web + + frontend-build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: "16" + cache: yarn + cache-dependency-path: "web/yarn.lock" + - run: yarn + working-directory: web + - name: Run frontend build + run: yarn build + working-directory: web + + go-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v3 + with: + go-version: 1.18 + check-latest: true + cache: true + - name: Run all tests + run: go test -v ./... | tee test.log; exit ${PIPESTATUS[0]} + - name: Pretty print tests running time + run: grep --color=never -e '--- PASS:' -e '--- FAIL:' test.log | sed 's/[:()]//g' | awk '{print $2,$3,$4}' | sort -t' ' -nk3 -r | awk '{sum += $3; print $1,$2,$3,sum"s"}' diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8917ea2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "go.lintOnSave": "workspace", + "go.lintTool": "golangci-lint" +}