diff --git a/.github/workflows/clippy-fmt.yml b/.github/workflows/clippy-fmt.yml new file mode 100644 index 00000000..9332b783 --- /dev/null +++ b/.github/workflows/clippy-fmt.yml @@ -0,0 +1,39 @@ +name: Lint + +on: + pull_request: + types: [opened, synchronize, reopened] + push: + branches: + - master + - db-abstract + +jobs: + fmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # Ensure rustfmt is installed and setup problem matcher + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: rustfmt + - name: Rustfmt Check + uses: actions-rust-lang/rustfmt@v1 + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: clippy + + - uses: actions/setup-node@v2 + with: + node-version: "20.0.0" + + - name: Build frontend + run: make frontend + + - name: clippy Check + run: cargo clippy --workspace --tests --all-features diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 00000000..5ebf339c --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,119 @@ +#name: Coverage +# +#on: +# pull_request: +# types: [opened, synchronize, reopened] +# push: +# branches: +# - master +# - db-abstract +# +#jobs: +# build_and_test: +# strategy: +# fail-fast: false +# matrix: +# version: +# - stable +# #- 1.51.0 +# +# name: ${{ matrix.version }} - x86_64-unknown-linux-gnu +# runs-on: ubuntu-latest +# +# services: +# postgres: +# image: postgres +# env: +# POSTGRES_PASSWORD: password +# POSTGRES_USER: postgres +# POSTGRES_DB: postgres +# options: >- +# --health-cmd pg_isready +# --health-interval 10s +# --health-timeout 5s +# --health-retries 5 +# ports: +# - 5432:5432 +# +# mcaptcha-redis: +# image: mcaptcha/cache +# ports: +# - 6379:6379 +# +# mcaptcha-smtp: +# image: maildev/maildev +# env: +# MAILDEV_WEB_PORT: "1080" +# MAILDEV_INCOMING_USER: "admin" +# MAILDEV_INCOMING_PASS: "password" +# ports: +# - 1080:1080 +# - 10025:1025 +# +# +# maria: +# image: mariadb:10 +# env: +# MARIADB_USER: "maria" +# MARIADB_PASSWORD: "password" +# MARIADB_ROOT_PASSWORD: "password" +# MARIADB_DATABASE: "maria" +# options: >- +# --health-cmd="mysqladmin ping" +# --health-interval=10s +# --health-timeout=5s +# --health-retries=10 +# ports: +# - 3306:3306 +# +# +# steps: +# - uses: actions/checkout@v4 +# +# - name: load env +# run: | +# source .env_sample \ +# && echo "POSTGRES_DATABASE_URL=$POSTGRES_DATABASE_URL" >> $GITHUB_ENV \ +# && echo "MARIA_DATABASE_URL=$MARIA_DATABASE_URL" >> $GITHUB_ENV +# +# +# - uses: actions/setup-node@v2 +# with: +# node-version: "18.0.0" +# +# - uses: actions-rust-lang/setup-rust-toolchain@v1 +# +# - name: Build frontend +# run: make frontend +# +# - name: Run the frontend tests +# run: make test.frontend +# +# - name: Run migrations +# run: make migrate +# env: +# POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" +# MARIA_DATABASE_URL: "${{ env.MARIA_DATABASE_URL }}" +# +# - name: build frontend +# run: make frontend +# +# - name: Generate coverage file +# if: github.event_name == 'pull_request' +# #if: (github.ref == 'refs/heads/master' || github.event_name == 'pull_request') +# uses: actions-rs/tarpaulin@v0.1 +# with: +# args: "-t 1200" +# env: +# POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" +# MARIA_DATABASE_URL: "${{ env.MARIA_DATABASE_URL }}" +# # GIT_HASH is dummy value. I guess build.rs is skipped in tarpaulin +# # execution so this value is required for preventing meta tests from +# # panicking +# GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61 +# CACHE_BUSTER_FILE_MAP: '{"map":{"./static/bundle/main.js":"./prod/bundle/main.1417115E59909BE0A01040A45A398ADB09D928DF89CCF038FA44B14850442096.js"},"base_dir":"./prod"}' +# COMPILED_DATE: "2021-07-21" +# +# - name: Upload to Codecov +# if: github.event_name == 'pull_request' +# uses: codecov/codecov-action@v2 diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml new file mode 100644 index 00000000..dcfd6664 --- /dev/null +++ b/.github/workflows/linux.yml @@ -0,0 +1,154 @@ +name: Build + +on: + schedule: + - cron: "0 9 * * *" + pull_request: + types: [opened, synchronize, reopened] + push: + branches: + - master + - "*" + - "!gh-pages" + +jobs: + build_and_test: + strategy: + fail-fast: false + matrix: + version: + - stable + + name: ${{ matrix.version }} - x86_64-unknown-linux-gnu + runs-on: ubuntu-latest + + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: password + POSTGRES_USER: postgres + POSTGRES_DB: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + mcaptcha-redis: + image: mcaptcha/cache + ports: + - 6379:6379 + mcaptcha-smtp: + image: maildev/maildev + env: + MAILDEV_WEB_PORT: "1080" + MAILDEV_INCOMING_USER: "admin" + MAILDEV_INCOMING_PASS: "password" + ports: + - 1080:1080 + - 10025:1025 + + maria: + image: mariadb:10 + env: + MARIADB_USER: "maria" + MARIADB_PASSWORD: "password" + MARIADB_ROOT_PASSWORD: "password" + MARIADB_DATABASE: "maria" + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=10 + ports: + - 3306:3306 + + steps: + - uses: actions/checkout@v4 + + + - name: configure GPG key + if: (github.ref == 'refs/heads/master' || github.event_name == 'push') && github.repository == 'mCaptcha/mCaptcha' + run: echo -n "$RELEASE_BOT_GPG_SIGNING_KEY" | gpg --batch --import --pinentry-mode loopback + env: + RELEASE_BOT_GPG_SIGNING_KEY: ${{ secrets.RELEASE_BOT_GPG_SIGNING_KEY }} + + - name: load env + run: | + source .env_sample \ + && echo "POSTGRES_DATABASE_URL=$POSTGRES_DATABASE_URL" >> $GITHUB_ENV \ + && echo "MARIA_DATABASE_URL=$MARIA_DATABASE_URL" >> $GITHUB_ENV + + - uses: actions/setup-node@v2 + with: + node-version: "20.0.0" + + - uses: actions-rust-lang/setup-rust-toolchain@v1 + + - name: install nightwatch dep + run: sudo apt-get install xvfb + + - name: Run migrations + run: make migrate + env: + POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" + MARIA_DATABASE_URL: "${{ env.MARIA_DATABASE_URL }}" + + - name: build + run: make + env: + POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" + MARIA_DATABASE_URL: "${{ env.MARIA_DATABASE_URL }}" + + # - name: build frontend + # run: make frontend + # + - name: lint frontend + run: yarn lint + + - name: run tests + run: make test + env: + POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" + MARIA_DATABASE_URL: "${{ env.MARIA_DATABASE_URL }}" + + - name: run integration tests + run: make test.integration + + - name: Login to DockerHub + if: github.ref == 'refs/heads/master' && github.event_name == 'push' && github.repository == 'mCaptcha/mCaptcha' + uses: docker/login-action@v1 + with: + username: mcaptcha + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: publish docker images + if: (github.ref == 'refs/heads/master' || github.event_name == 'push') && github.repository == 'mCaptcha/mCaptcha' + run: make docker-publish + + - name: publish bins + if: (github.ref == 'refs/heads/master' || github.event_name == 'push') && github.repository == 'mCaptcha/mCaptcha' + run: ./scripts/publish.sh publish master latest $DUMBSERVE_PASSWORD + env: + DUMBSERVE_PASSWORD: ${{ secrets.DUMBSERVE_PASSWORD }} + GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }} + + - name: generate documentation + if: matrix.version == 'stable' && (github.repository == 'mCaptcha/mCaptcha') + run: make doc + env: + POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" + MARIA_DATABASE_URL: "${{ env.MARIA_DATABASE_URL }}" + GIT_HASH: 8e77345f1597e40c2e266cb4e6dee74888918a61 # dummy value + COMPILED_DATE: "2021-07-21" + + - name: Deploy to GitHub Pages + if: matrix.version == 'stable' && (github.repository == 'mCaptcha/mCaptcha') + uses: JamesIves/github-pages-deploy-action@3.7.1 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: gh-pages + FOLDER: target/doc diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..6b9cd5ce --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,125 @@ +name: Publish release + +on: + release: + type: [published] + +jobs: + build_and_test: + strategy: + fail-fast: false + + name: x86_64-unknown-linux-gnu + runs-on: ubuntu-latest + + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: password + POSTGRES_USER: postgres + POSTGRES_DB: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + mcaptcha-redis: + image: mcaptcha/cache + ports: + - 6379:6379 + mcaptcha-smtp: + image: maildev/maildev + env: + MAILDEV_WEB_PORT: "1080" + MAILDEV_INCOMING_USER: "admin" + MAILDEV_INCOMING_PASS: "password" + ports: + - 1080:1080 + - 10025:1025 + + maria: + image: mariadb:10 + env: + MARIADB_USER: "maria" + MARIADB_PASSWORD: "password" + MARIADB_ROOT_PASSWORD: "password" + MARIADB_DATABASE: "maria" + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=10 + ports: + - 3306:3306 + + steps: + - uses: actions/checkout@v4 + + - name: configure GPG key + run: echo -n "$RELEASE_BOT_GPG_SIGNING_KEY" | gpg --batch --import --pinentry-mode loopback + env: + RELEASE_BOT_GPG_SIGNING_KEY: ${{ secrets.RELEASE_BOT_GPG_SIGNING_KEY }} + + - name: Set release version + run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + + - name: load env + run: | + source .env_sample \ + && echo "POSTGRES_DATABASE_URL=$POSTGRES_DATABASE_URL" >> $GITHUB_ENV \ + && echo "MARIA_DATABASE_URL=$MARIA_DATABASE_URL" >> $GITHUB_ENV + + - uses: actions/setup-node@v2 + with: + node-version: "20.0.0" + + - uses: actions-rust-lang/setup-rust-toolchain@v1 + + - name: install nightwatch dep + run: sudo apt-get install xvfb + + - name: Run migrations + run: make migrate + env: + POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" + MARIA_DATABASE_URL: "${{ env.MARIA_DATABASE_URL }}" + + - name: build + run: make + env: + POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" + MARIA_DATABASE_URL: "${{ env.MARIA_DATABASE_URL }}" + + - name: lint frontend + run: yarn lint + + - name: run tests + run: make test + env: + POSTGRES_DATABASE_URL: "${{ env.POSTGRES_DATABASE_URL }}" + MARIA_DATABASE_URL: "${{ env.MARIA_DATABASE_URL }}" + + - name: run integration tests + run: make test.integration + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: mcaptcha + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: build docker images + run: docker build -t mcaptcha/mcaptcha:${RELEASE_VERSION} . + + - name: publish docker images + run: docker push mcaptcha/mcaptcha:${RELEASE_VERSION} + + - name: publish bins + run: ./scripts/publish.sh publish $RELEASE_VERSION latest $DUMBSERVE_PASSWORD + env: + DUMBSERVE_PASSWORD: ${{ secrets.DUMBSERVE_PASSWORD }} + GPG_PASSWORD: ${{ secrets.GPG_PASSWORD }} diff --git a/.github/workflows/tagged-release.yml b/.github/workflows/tagged-release.yml new file mode 100644 index 00000000..d133cbf4 --- /dev/null +++ b/.github/workflows/tagged-release.yml @@ -0,0 +1,32 @@ +#name: Create binary for release +# +## Only on tags that start with a "v" +#on: +# push: +# tags: +# - "v*" +# +#jobs: +# build: +# runs-on: ubuntu-latest +# strategy: +# fail-fast: false +# matrix: +# include: +# - target: x86_64-pc-windows-gnu +# archive: zip +# - target: x86_64-unknown-linux-musl +# archive: tar.gz tar.xz +# - target: x86_64-apple-darwin +# archive: zip +# steps: +# - name: Checkout +# uses: actions/checkout@v3 +# +# - name: Compile and release +# uses: rust-build/rust-build.action@v1.3.2 +# env: +# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} +# with: +# RUSTTARGET: ${{ matrix.target }} +# ARCHIVE_TYPES: ${{ matrix.archive }}