From 70cbe6b07a69751b9b0c69b03b86f175186ea3f2 Mon Sep 17 00:00:00 2001 From: a-givertzman Date: Thu, 25 Apr 2024 12:35:12 +0300 Subject: [PATCH] Build deb | github action --- .github/workflows/markdownlint.yaml | 38 ++++++++++++ .github/workflows/packaging/deb/build.sh | 2 +- .../packaging/deb/service}/api-server.service | 0 .github/workflows/release_deb_package.yaml | 59 +++++++++++++++++++ .github/workflows/test.yaml | 30 +++++----- 5 files changed, 114 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/markdownlint.yaml rename {service => .github/workflows/packaging/deb/service}/api-server.service (100%) create mode 100644 .github/workflows/release_deb_package.yaml diff --git a/.github/workflows/markdownlint.yaml b/.github/workflows/markdownlint.yaml new file mode 100644 index 00000000..01da110c --- /dev/null +++ b/.github/workflows/markdownlint.yaml @@ -0,0 +1,38 @@ +# Markdownlint configuration +# refet to the documentation for details: +# - [Linter for markdown](https://github.com/avto-dev/markdown-lint) +# - [Rules configuration](https://github.com/DavidAnson/markdownlint/blob/main/schema/.markdownlint.yaml) +# - [github](https://github.com/markdownlint/markdownlint?tab=readme-ov-file) +# Default state for all rules +default: true + +# Path to configuration file to extend +extends: null + +# MD013/line-length : Line length : https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md013.md +MD013: + # Number of characters + line_length: 160 + # Number of characters for headings + heading_line_length: 80 + # Number of characters for code blocks + code_block_line_length: 160 + # Include code blocks + code_blocks: true + # Include tables + tables: true + # Include headings + headings: true + # Strict length checking + strict: false + # Stern length checking + stern: false + +# MD033/no-inline-html : Inline HTML : https://github.com/DavidAnson/markdownlint/blob/v0.34.0/doc/md033.md +MD033: + # Allowed elements + allowed_elements: [ + details, + summary, + ] + \ No newline at end of file diff --git a/.github/workflows/packaging/deb/build.sh b/.github/workflows/packaging/deb/build.sh index 2019ed6f..f63a7f1d 100755 --- a/.github/workflows/packaging/deb/build.sh +++ b/.github/workflows/packaging/deb/build.sh @@ -3,7 +3,7 @@ # ############ LIST OF MANAGED VARIABLES REQUIRED FOR DEB PACKAGE ############ name=api-server -# version=x.y.z - reading late from first arg $1 +# version=x.y.z - reading from first arg $1 descriptionShort="API Server wrapping databases, executable and python scripts plugins" descriptionExtended="API Server - service running on the socket. Provides simple and universe access to the databases, executable and python plugins. diff --git a/service/api-server.service b/.github/workflows/packaging/deb/service/api-server.service similarity index 100% rename from service/api-server.service rename to .github/workflows/packaging/deb/service/api-server.service diff --git a/.github/workflows/release_deb_package.yaml b/.github/workflows/release_deb_package.yaml new file mode 100644 index 00000000..ac318a2f --- /dev/null +++ b/.github/workflows/release_deb_package.yaml @@ -0,0 +1,59 @@ +name: Create release with beb pacage + +on: + workflow_dispatch: + +env: + TERM: dumb + CARGO_TERM_COLOR: always + API_SERVER_ADDR: '0.0.0.0' + API_SERVER_PORT: 8080 + POSTGRES_PASSWORD: postgres + PYTHON_VERSION: 'python3.10' + +jobs: + build_and_test: + name: Creating new release with beb pacage + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Update version number in the Cargo.toml + run: | + old_version_var=$(cat ./Cargo.toml | sed -rn 's/^version[\t ]*=[\t ]*\"([0-9]+\.[0-9]+\.[0-9]+)\"\s*$/\1/gp') + echo "old version: $old_version_var" + echo "new build: ${{ github.run_number }}" + sed -i -r "s/^(version[\t ]*=[\t ]*\"[0-9]+\.[0-9]+\.)[0-9]+\"\s*$/\1${{ github.run_number }}\"/g" ./Cargo.toml + new_version_var=$(cat ./Cargo.toml | sed -rn 's/^version[\t ]*=[\t ]*\"([0-9]+\.[0-9]+\.[0-9]+)\"\s*$/\1/gp') + echo "new version: $new_version_var" + echo "NEW_VERSION=$new_version_var" >> $GITHUB_ENV + echo "new version: ${{ env.NEW_VERSION }}" + + - name: Build release + run: cargo build --release + + - name: Commit new version ${{ env.NEW_VERSION }} + run: | + echo "on repositiry: ${{ github.repository }}" + git config --global user.name 'anton.lobanov' + git config --global user.email 'lobanov.anton@gmail.com' + git remote set-url origin https://a-givertzman:${{ secrets.RELEASES_TOKEN }}@github.com/${{ github.repository }} + git commit -am "Automated version update to: ${{ env.NEW_VERSION }}" + + - name: Push to protected branch "master" + uses: CasperWA/push-protected@v2 + with: + token: ${{ secrets.RELEASES_TOKEN }} + branch: master + unprotect_reviews: true + + - name: Zip artifact for deployment + run: zip ./target/release/release.zip -r ./target/release/* ./config.yaml ./extensions/* + + - name: Publish release + uses: ncipollo/release-action@v1 + with: + artifacts: "./target/release/release.zip" + tag: internal_v${{ env.NEW_VERSION }} + token: ${{ secrets.RELEASES_TOKEN }} diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2ca4b423..a53d0553 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -16,14 +16,6 @@ jobs: build_and_test: name: Testing runs-on: ubuntu-latest - # strategy: - # matrix: - # toolchain: - # - stable - # - beta - # - nightly - - # Service containers to run with `container-job` services: # Label used to access the service container @@ -55,15 +47,25 @@ jobs: toolchain: stable override: true - # - name: Static analisis - # run: | - # cargo check - # # - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} - # # - run: cargo build --release + - name: Static analysis | Markdown lint tool + uses: docker://avtodev/markdown-lint:v1 + with: + config: '.github/workflows/markdownlint.yaml' + args: "**/*.md" + - name: Static analysis | cargo check + run: | + cargo check + - name: Static analysis | cargo clippy + run: | + cargo clippy + # cargo fmt --check + - name: Static analysis | cargo fmt + run: | + echo "escaped for now because of to much of errors, will be turned on later" + # cargo fmt --check - name: Unit tests run: cargo test -- --show-output - - name: Integration tests run: |