From 15175b5bb3478e0ef5c16fe5b91205c6808a3f34 Mon Sep 17 00:00:00 2001 From: sarmstrong Date: Fri, 22 Dec 2023 11:48:11 +0300 Subject: [PATCH 1/4] Actions add node tempate --- .../node-pull-request-check-template.yml | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 .gitea/workflows/node-pull-request-check-template.yml diff --git a/.gitea/workflows/node-pull-request-check-template.yml b/.gitea/workflows/node-pull-request-check-template.yml new file mode 100644 index 0000000..bf47774 --- /dev/null +++ b/.gitea/workflows/node-pull-request-check-template.yml @@ -0,0 +1,109 @@ +name: Pull request check +on: + workflow_call: + inputs: + notification_enabled: + description: "Включение оповещений о разворачивании, требуется иметь url для оповещений в vault" + default: false + required: false + type: boolean + custom_notification_hook_enabled: + description: "Использовать ли кастомный url хук для оповещений (должен лежать в vault секрете проекта)" + default: false + required: false + type: boolean + notification_channel: + description: "Канал для оповещений о результатах деплоя" + default: internal_projects_notifications + required: false + type: string + vault_secrets_base_path: + description: 'Базовый путь для секретов проекта в vault' + required: false + type: string + gradle_check_command: + description: 'Команда для исполнения в gradle' + default: 'test' + required: false + type: string + sonar_enabled: + default: false + required: false + type: boolean + secrets: + VAULT_ROLE_ID: + required: true + VAULT_SECRET_ID: + required: true + +env: + vault_main_base_path: dev/wilix/main/data/ci + +jobs: + check: + name: check and test + runs-on: ubuntu-latest + steps: + - uses: https://github.com/actions/checkout@v3 + - uses: https://github.com/actions/checkout@v3 + - name: Use Node.js 20 + uses: https://github.com/actions/setup-node@v3 + with: + node-version: 20 + - run: yarn install + - run: yarn test + + - name: dockerfile lint check + uses: https://github.com/hadolint/hadolint-action@v3.1.0 + with: + dockerfile: Dockerfile + + - name: Get general notification url + if: ${{ inputs.notification_enabled && ! inputs.custom_notification_hook_enabled && (job.status == 'success' || job.status == 'failure') }} + uses: https://github.com/hashicorp/vault-action@v2 + with: + url: https://vault.wilix.dev + method: approle + roleId: ${{ secrets.VAULT_ROLE_ID }} + secretId: ${{ secrets.VAULT_SECRET_ID }} + secrets: | + ${{ env.vault_main_base_path }} notification_url | MATTERMOST_WEBHOOK_URL ; + + - name: Get custom notification url + if: ${{ inputs.notification_enabled && inputs.custom_notification_hook_enabled && (job.status == 'success' || job.status == 'failure') }} + uses: https://github.com/hashicorp/vault-action@v2 + with: + url: https://vault.wilix.dev + method: approle + roleId: ${{ secrets.VAULT_ROLE_ID }} + secretId: ${{ secrets.VAULT_SECRET_ID }} + secrets: | + ${{ inputs.vault_secrets_base_path }} notification_url | MATTERMOST_WEBHOOK_URL ; + + - name: prepare failed notification body + if: ${{ inputs.notification_enabled && job.status == 'failure' }} + uses: https://github.com/finnp/create-file-action@master + env: + FILE_NAME: "mattermost.json" + FILE_DATA: | + { + "channel": "${{ inputs.notification_channel }}", + "attachments": [ + { + "fallback": "Проверка упала ${{ gitea.repository }}", + "text": "@${{ gitea.actor }} упала тестовая сборка", + "color": "#FF0000", + "fields": [ + { + "short": true, + "title": "Сборка", + "value": "https://git.wilix.dev/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}" + } + ] + } + ] + } + + - name: loop fail notification + if: ${{ inputs.notification_enabled && job.status == 'failure' }} + uses: https://github.com/mattermost/action-mattermost-notify@master -- 2.40.1 From a955139aa0c4ed0e3f85981c4db4f906878773a3 Mon Sep 17 00:00:00 2001 From: sarmstrong Date: Fri, 22 Dec 2023 11:52:02 +0300 Subject: [PATCH 2/4] Remove double entry and gradle. --- .gitea/workflows/node-pull-request-check-template.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.gitea/workflows/node-pull-request-check-template.yml b/.gitea/workflows/node-pull-request-check-template.yml index bf47774..164408c 100644 --- a/.gitea/workflows/node-pull-request-check-template.yml +++ b/.gitea/workflows/node-pull-request-check-template.yml @@ -21,11 +21,6 @@ on: description: 'Базовый путь для секретов проекта в vault' required: false type: string - gradle_check_command: - description: 'Команда для исполнения в gradle' - default: 'test' - required: false - type: string sonar_enabled: default: false required: false @@ -44,7 +39,6 @@ jobs: name: check and test runs-on: ubuntu-latest steps: - - uses: https://github.com/actions/checkout@v3 - uses: https://github.com/actions/checkout@v3 - name: Use Node.js 20 uses: https://github.com/actions/setup-node@v3 -- 2.40.1 From 08596cf178f8ed3f5715916078528e68286e3e2b Mon Sep 17 00:00:00 2001 From: sarmstrong Date: Fri, 22 Dec 2023 12:56:58 +0300 Subject: [PATCH 3/4] Add multi-project support. --- .../node-pull-request-check-template.yml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/node-pull-request-check-template.yml b/.gitea/workflows/node-pull-request-check-template.yml index 164408c..cd9dfeb 100644 --- a/.gitea/workflows/node-pull-request-check-template.yml +++ b/.gitea/workflows/node-pull-request-check-template.yml @@ -2,6 +2,18 @@ name: Pull request check on: workflow_call: inputs: + node-version: + description: "Set node version" + default: 20 + required: true + type: string + yarn-commands: + description: "yarn-commands" + default: |- + yarn install + yarn test + required: true + type: string notification_enabled: description: "Включение оповещений о разворачивании, требуется иметь url для оповещений в vault" default: false @@ -40,12 +52,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: https://github.com/actions/checkout@v3 - - name: Use Node.js 20 + - name: Use Node.js ${{ inputs.node-version }} uses: https://github.com/actions/setup-node@v3 with: - node-version: 20 - - run: yarn install - - run: yarn test + node-version: ${{ inputs.node-version }} + - run: ${{ inputs.yarn-commands }} - name: dockerfile lint check uses: https://github.com/hadolint/hadolint-action@v3.1.0 -- 2.40.1 From b42c130ed2552f795d6de46fb9b491542f2fff1c Mon Sep 17 00:00:00 2001 From: sarmstrong Date: Fri, 22 Dec 2023 13:25:15 +0300 Subject: [PATCH 4/4] Remove required. --- .gitea/workflows/node-pull-request-check-template.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitea/workflows/node-pull-request-check-template.yml b/.gitea/workflows/node-pull-request-check-template.yml index cd9dfeb..0d4bdd3 100644 --- a/.gitea/workflows/node-pull-request-check-template.yml +++ b/.gitea/workflows/node-pull-request-check-template.yml @@ -5,14 +5,12 @@ on: node-version: description: "Set node version" default: 20 - required: true type: string yarn-commands: description: "yarn-commands" default: |- yarn install yarn test - required: true type: string notification_enabled: description: "Включение оповещений о разворачивании, требуется иметь url для оповещений в vault" -- 2.40.1