Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #129

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open

test #129

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
44afa03
ci: добавлен commit-lint и husky
qzeene Jul 13, 2023
1809cfb
ci: добавлен pull-request workflow
qzeene Jul 13, 2023
6e052b6
ci: npx eslint
qzeene Jul 13, 2023
30e3299
ci: headless e2e
qzeene Jul 13, 2023
cc071d6
ci: commitlint
qzeene Jul 13, 2023
a89caaf
ci: отказ от push
qzeene Jul 13, 2023
86d8bd8
ci: fetch-depth for commitlint
qzeene Jul 13, 2023
5bf9aec
ci: start release.yml
qzeene Jul 15, 2023
7bf0f92
ci: fix
qzeene Jul 15, 2023
1744109
ci: fix
qzeene Jul 15, 2023
0acc5f4
ci: fix
qzeene Jul 15, 2023
0028527
ci: fix
qzeene Jul 15, 2023
17a9434
ci: fix
qzeene Jul 15, 2023
dff4b4a
ci: fix
qzeene Jul 15, 2023
3af8c6a
ci: fix
qzeene Jul 15, 2023
c8a368a
ci: fix
qzeene Jul 15, 2023
598375a
ci: fix
qzeene Jul 15, 2023
35cbaba
ci: fix
qzeene Jul 15, 2023
ace1786
ci: fix
qzeene Jul 15, 2023
ac05835
ci: fix
qzeene Jul 15, 2023
fbde921
ci: fix
qzeene Jul 15, 2023
75b3eb0
ci: fix
qzeene Jul 15, 2023
669261a
ci: fix
qzeene Jul 15, 2023
406fde0
ci: issue
qzeene Jul 15, 2023
1ce3c82
ci: issue
qzeene Jul 15, 2023
4f7c31d
ci: issue
qzeene Jul 15, 2023
2f7b57a
ci: issue
qzeene Jul 15, 2023
0dfdf95
ci: issue
qzeene Jul 15, 2023
c3ff860
ci: issue
qzeene Jul 15, 2023
6375e88
ci: issue
qzeene Jul 15, 2023
19ab191
ci: issue
qzeene Jul 15, 2023
8b53a6e
ci: issue
qzeene Jul 15, 2023
d76e658
ci: issue comment
qzeene Jul 15, 2023
44007ca
ci: issue comment
qzeene Jul 15, 2023
ee8c6e9
ci: test-and-lint
qzeene Jul 15, 2023
4194719
test: сломанный тест кейс
qzeene Jul 15, 2023
fafc2af
test: сломанный e2e тест кейс
qzeene Jul 15, 2023
7613994
ci: fixes
qzeene Jul 15, 2023
7185cc2
ci: update yml
qzeene Jul 15, 2023
b864d84
feat: add public url variable
qzeene Jul 16, 2023
b093616
fix: e2e test
qzeene Jul 16, 2023
bcff335
fix: module test
qzeene Jul 16, 2023
693c3d6
fix: basename for browser router
qzeene Jul 16, 2023
1adda5e
docs: добавлен описание в readme
qzeene Jul 16, 2023
eadd48e
fix: test_1
SaimonWELL Jul 19, 2023
7b6c707
fix:test_2
SaimonWELL Jul 19, 2023
b431694
uncorrect
SaimonWELL Jul 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .commitlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"@commitlint/config-conventional"
]
}
10 changes: 10 additions & 0 deletions .github/release-issue-template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: RELEASE {{env.RELEASE}}
labels: release
---
Релиз: {{env.RELEASE}}
Релизная ветка: {{env.RELEASE_BRANCH}}
Автор: {{env.RELEASE_AUTHOR}}
Дата: {{env.RELEASE_DATE}}

{{env.RELEASE_BODY}}
62 changes: 62 additions & 0 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Lint and run test
on:
workflow_call:
inputs:
commit-from:
required: true
type: string
commit-to:
required: true
type: string

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install deps
run: npm ci
- name: Eslint checks
run: npx eslint .
- name: Validate commits with commitlint
run: npx commitlint --from ${{ inputs.commit-from }} --to ${{ inputs.commit-to }} --verbose

unit-tests:
runs-on: ubuntu-latest
needs: lint
env:
CI: true
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install deps
run: npm ci
- name: Run unit tests
run: npm run test

e2e-tests:
runs-on: ubuntu-latest
needs: lint
env:
CI: true
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- run: npm ci
- run: npx playwright install chromium --with-deps
- run: npm run e2e
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
11 changes: 11 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: pull-request
on:
pull_request:
branches: [ "master" ]

jobs:
lint-and-tests:
uses: ./.github/workflows/lint-and-test.yml
with:
commit-from: ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }}
commit-to: ${{ github.event.pull_request.head.sha }}
194 changes: 194 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
name: Release
on:
push:
branches:
- "releases/v[0-9]+"
tags:
- "v[0-9]+"

jobs:
create-new-issue:
if: contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
outputs:
issueId: ${{ steps.create-issue.outputs.number }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- id: new-branch
run: |
id=$(echo "${{github.ref}}" | cut -d / -f3)
branch=releases/$id

git checkout -b $branch
git push --set-upstream origin $branch

echo "RELEASE=$id" >> $GITHUB_ENV
echo "RELEASE_BRANCH=$branch" >> $GITHUB_ENV
echo "RELEASE_AUTHOR=$(git for-each-ref --format="%(authorname) %(authoremail)" refs/tags/$id)" >> $GITHUB_ENV
echo "RELEASE_DATE=$(git for-each-ref --format="%(authordate)" refs/tags/$id)" >> $GITHUB_ENV

LOG=$(git log $(git describe --tags --abbrev=0 --exclude=$id)..HEAD --oneline)
echo "RELEASE_BODY<<EOF" >> $GITHUB_ENV
echo "$LOG" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: JasonEtco/create-an-issue@v2
with:
filename: .github/release-issue-template.md
update_existing: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
id: create-issue
- run: 'echo Created issue number ${{ steps.create-issue.outputs.number }}'
- run: 'echo Created ${{ steps.create-issue.outputs.url }}'

get-issue-id:
needs: create-new-issue
if: always()
runs-on: ubuntu-latest
outputs:
issueId: ${{ steps.get-issue-id.outputs.result }}
steps:
- id: get-version
run: |
echo $(version=$(echo "${{github.ref}}" | cut -d / -f4)) >> $GITHUB_OUTPUT

- uses: actions/github-script@v6
id: get-issue-id
with:
script: |
if ("${{needs.create-new-issue.outputs.issueId}}" !== "") {
return ${{needs.create-new-issue.outputs.issueId}}
}

const {GITHUB_REPOSITORY} = process.env
const result = await github.rest.search.issuesAndPullRequests({
q: `is:issue is:open repo:${GITHUB_REPOSITORY} in:title "RELEASE ${{ steps.get-version.version }}"`,
})

if (result.data?.items?.length === 1) {
return result.data.items[0].number;
}

console.log(result)
throw new Error("Issue не найдена")


write-changelog-comment:
runs-on: ubuntu-latest
if: always() && contains(github.ref, 'refs/heads/')
needs: get-issue-id
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- id: get-changelog
run: |
LOG=$(git log ${{ github.event.before }}..${{ github.event.after }} --oneline)
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
echo "$LOG" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- uses: actions/github-script@v6
with:
script: |
const {CHANGELOG} = process.env
github.rest.issues.createComment({
issue_number: ${{ needs.get-issue-id.outputs.issueId }},
owner: context.repo.owner,
repo: context.repo.repo,
body: `Добавлены изменения в релиз:\n\n${CHANGELOG}`
})


lint-and-test:
needs: get-issue-id
if: always()
uses: ./.github/workflows/lint-and-test.yml
with:
commit-from: ${{ startsWith(github.ref, 'refs/heads/') && github.event.before || '$(git describe --tags --abbrev=0 --exclude=$(echo "${{github.ref}}" | cut -d / -f4))' }}
commit-to: ${{ startsWith(github.ref, 'refs/heads/') && github.event.after || github.ref }}

write-result-comment:
runs-on: ubuntu-latest
if: always()
needs:
- lint-and-test
- get-issue-id
steps:
- uses: actions/github-script@v6
with:
script: |
let body = "";
if ("${{needs.lint-and-test.result}}" === "failure") {
body = "❌Этап линтинга и тестов не пройден. Подробнее: "
} else {
body = "✅Этап линтинга и тестов успешно пройден. Подробнее: "
}

body += "\n\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"

github.rest.issues.createComment({
issue_number: ${{ needs.get-issue-id.outputs.issueId }},
owner: context.repo.owner,
repo: context.repo.repo,
body,
})


build-and-deploy:
needs: lint-and-test
if: always() && success()
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v3
with:
node-version: 18

- name: Checkout 🛎️
uses: actions/checkout@v3

- name: Install and Build
run: |
npm ci
npm run build

- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: build

close-release-issue:
needs:
- build-and-deploy
- get-issue-id
- write-result-comment
if: always() && needs.build-and-deploy.result != 'skipped'
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
let body = "";
if ("${{needs.build-and-deploy.result}}" === "failure") {
body = "❌Не удалось задеплоить проект на gh-pages"
} else {
body = "🚀Проект опубликован. Релиз завершен"
}

await github.rest.issues.createComment({
issue_number: ${{ needs.get-issue-id.outputs.issueId }},
owner: context.repo.owner,
repo: context.repo.repo,
body,
})

if ("${{needs.build-and-deploy.result}}" === "success") {
await github.rest.issues.update({
issue_number: ${{ needs.get-issue-id.outputs.issueId }},
owner: context.repo.owner,
repo: context.repo.repo,
state: "closed",
state_reason: "completed"
})
}
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit ${1}
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# Инфраструктура

ТГ для связи - [@q2een_dev](https://t.me/q2een_dev)

## Логика ci

### PR
* eslint + commitlint для коммитов в текущем PR
* e2e тесты - результат сохраняется в артифакты
* модульные тесты

yml - pull-request.yml

### Release
* срабатывает на тег вида `v<число>` или на пуш в ветку с именем `releases/v<число>`
* если событие - пуш тега - создается/обновляется issue, содержащее информацию о релизе - changelog, автор, дата, версия релиза, релизная ветка
* если событие - пуш в релизную ветку - в существующий issue добавляется комментарий c чейнджлогом на основе коммитов в данном пуше
* выполняются шаги, идентичные PR
* в issue релиза пишется комментарий со ссылкой на workflow и текстом успешности выполнения workflow
* если все тесты пройдены - деплой приложения
* в issue добаляется комментарий о результате деплоя. Если успех - закрывается issue=-0



В этом репозитории находится пример приложения с тестами:

- [e2e тесты](e2e/example.spec.ts)
Expand Down
Loading