-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/initial
- Loading branch information
Showing
9 changed files
with
983 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
name: Build | ||
run-name: 'Build: @${{ github.ref_name }}' | ||
on: | ||
push: | ||
tags: | ||
- 'v*' | ||
|
||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GH_EMAIL: '41898282+github-actions[bot]@users.noreply.github.com' | ||
GH_USER: 'github-actions[bot]' | ||
|
||
jobs: | ||
build: | ||
name: Build applications | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/[email protected] | ||
|
||
- name: Setup node (20.x) | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'pnpm' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Build | ||
run: pnpm run build | ||
|
||
- name: Publish | ||
run: pnpm publish --provenance | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
coverage: | ||
name: Upload the coverage | ||
needs: | ||
- build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/[email protected] | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '18.x' | ||
cache: 'pnpm' | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Run the coverage | ||
run: pnpm run coverage | ||
|
||
- uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
files: ./coverage/coverage-final.json | ||
verbose: true | ||
|
||
create-release: | ||
needs: | ||
- build | ||
name: Create Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Create Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | ||
with: | ||
tag_name: ${{ github.ref_name }} | ||
release_name: ${{ github.ref_name }} | ||
draft: true | ||
prerelease: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
name: CD | ||
run-name: 'CD for PR: #${{github.event.pull_request.number}} ${{ github.event.pull_request.title }}' | ||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
branches: | ||
- main | ||
|
||
concurrency: | ||
group: cd-${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GH_EMAIL: '41898282+github-actions[bot]@users.noreply.github.com' | ||
GH_USER: 'github-actions[bot]' | ||
|
||
jobs: | ||
check-release: | ||
name: Check release | ||
if: ${{ startsWith(github.head_ref, 'release/') && github.event.pull_request.merged == true }} | ||
runs-on: ubuntu-latest | ||
outputs: | ||
is_release: ${{ steps.check.outputs.is_release }} | ||
steps: | ||
- name: check | ||
id: check | ||
run: | | ||
SOURCE="${{ github.head_ref }}" | ||
TARGET="${{ github.base_ref }}" | ||
VAR_NAME="is_release" | ||
if [[ ${SOURCE} == release/* ]] && [[ ${TARGET} == "main" ]]; then | ||
RESULT="${VAR_NAME}=1" | ||
else | ||
RESULT="${VAR_NAME}=0" | ||
fi | ||
echo "${RESULT}" | ||
echo "${RESULT}" >>"${GITHUB_OUTPUT}" | ||
test: | ||
needs: | ||
- check-release | ||
if: ${{ needs.check-release.outputs.is_release > 0 }} | ||
uses: ./.github/workflows/test.yml | ||
|
||
get-version: | ||
name: get version | ||
needs: | ||
- check-release | ||
if: ${{ startsWith(github.head_ref, 'release/') && (needs.check-release.outputs.is_release > 0)}} | ||
uses: ./.github/workflows/version.yml | ||
|
||
tag: | ||
name: Add the tag for the released version | ||
needs: | ||
- test | ||
- check-release | ||
- get-version | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/create-github-app-token@v1 | ||
id: app-token | ||
with: | ||
# required | ||
app-id: ${{ vars.APP_ID }} | ||
private-key: ${{ secrets.PRIVATE_KEY }} | ||
owner: ${{ github.repository_owner }} | ||
|
||
- name: Get GitHub App User ID | ||
id: get-user-id | ||
env: | ||
USER_NAME: ${{ steps.app-token.outputs.app-slug }} | ||
run: echo "user-id=$(gh api "/users/${USER_NAME}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Configration for git | ||
env: | ||
USER_ID: ${{ steps.get-user-id.outputs.user-id }} | ||
USER_NAME: ${{ steps.app-token.outputs.app-slug }} | ||
run: | | ||
git config --global user.name "${USER_NAME}[bot]" | ||
git config --global user.email "${USER_ID}+${USER_NAME}[bot]@users.noreply.github.com>" | ||
- name: Checkout | ||
env: | ||
GH_TOKEN: ${{ steps.app-token.outputs.token }} | ||
uses: actions/checkout@v4 | ||
with: | ||
token: ${{ env.GH_TOKEN }} | ||
|
||
- name: Add the release tag | ||
env: | ||
GH_TOKEN: ${{ steps.app-token.outputs.token }} | ||
APP_VERSION_TEXT: ${{ needs.get-version.outputs.app-version-text }} | ||
run: | | ||
echo "Create tag: ${APP_VERSION_TEXT}" | ||
git tag "${APP_VERSION_TEXT}" | ||
git push origin "${APP_VERSION_TEXT}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
name: Check tasks for pull request | ||
on: | ||
workflow_call: | ||
secrets: | ||
private-key: | ||
required: true | ||
outputs: | ||
is-updated: | ||
description: 'return 1 when Something was changed, otherwise 0' | ||
value: ${{ jobs.update-source-code.outputs.is-updated }} | ||
|
||
env: | ||
GH_EMAIL: '41898282+github-actions[bot]@users.noreply.github.com' | ||
GH_USER: 'github-actions[bot]' | ||
|
||
jobs: | ||
get-version: | ||
name: Get version to be released | ||
runs-on: ubuntu-latest | ||
if: ${{ startsWith(github.head_ref, 'release/') }} | ||
outputs: | ||
app-version: ${{ steps.get-version.outputs.app-version }} | ||
steps: | ||
- name: Get version to be released | ||
id: get-version | ||
run: | | ||
BRANCH_NAME="${{ github.head_ref }}" | ||
APP_VERSION_TEXT=${BRANCH_NAME##*/} | ||
APP_VERSION="$(echo "${APP_VERSION_TEXT}"| grep -o -E "([0-9]+\.){1}[0-9]+(\.[0-9]+)?")" | ||
echo "app-version-text=${APP_VERSION_TEXT}" >>"${GITHUB_OUTPUT}" | ||
echo "app-version=${APP_VERSION}" >>"${GITHUB_OUTPUT}" | ||
echo "detected version: ${APP_VERSION}" | ||
update-source-code: | ||
name: Format and lint | ||
runs-on: ubuntu-latest | ||
needs: | ||
- get-version | ||
if: ${{ !cancelled() && !failure() }} | ||
outputs: | ||
is-updated: ${{ steps.result.outputs.is-updated }} | ||
env: | ||
VAR_NAME_FOR_CHANGED: done-change | ||
steps: | ||
- uses: actions/create-github-app-token@v1 | ||
id: app-token | ||
with: | ||
# required | ||
app-id: ${{ vars.APP_ID }} | ||
private-key: ${{ secrets.private-key }} | ||
owner: ${{ github.repository_owner }} | ||
|
||
- name: Get GitHub App User ID | ||
id: get-user-id | ||
env: | ||
USER_NAME: ${{ steps.app-token.outputs.app-slug }} | ||
run: echo "user-id=$(gh api "/users/${USER_NAME}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Configration for git | ||
env: | ||
USER_ID: ${{ steps.get-user-id.outputs.user-id }} | ||
USER_NAME: ${{ steps.app-token.outputs.app-slug }} | ||
run: | | ||
git config --global user.name "${USER_NAME}[bot]" | ||
git config --global user.email "${USER_ID}+${USER_NAME}[bot]@users.noreply.github.com>" | ||
- name: Checkout | ||
env: | ||
GH_TOKEN: ${{ steps.app-token.outputs.token }} | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
token: ${{ env.GH_TOKEN }} | ||
|
||
- name: Install pnpm | ||
uses: pnpm/[email protected] | ||
|
||
- name: Setup node (20.x) | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: 'pnpm' | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: format | ||
run: pnpm run format | ||
|
||
- name: lint | ||
run: pnpm run lint | ||
|
||
- name: Check if there are any changes | ||
id: check-changes-fomat-lint | ||
run: | | ||
git add -N . | ||
if git diff --exit-code --quiet; then | ||
echo "No changes detected." | ||
RESULT="${VAR_NAME_FOR_CHANGED}=0" | ||
else | ||
echo "Changes detected." | ||
git add . | ||
git commit -m "style: format and lint source codes" -m "[AUTO]" | ||
RESULT="${VAR_NAME_FOR_CHANGED}=1" | ||
fi | ||
echo "${RESULT}">>"${GITHUB_OUTPUT}" | ||
echo "${RESULT}" | ||
- name: update package.json | ||
env: | ||
APP_VERSION: ${{ needs.get-version.outputs.app-version }} | ||
run: | | ||
test -z "${APP_VERSION}" && exit 0 | ||
echo "Try to update package.json" | ||
echo "-- before" | ||
cat package.json|grep version | ||
sed -i -e "s/\(\"version\": \"\).*\(\"\)/\1${APP_VERSION}\2/" package.json | ||
echo "-- after" | ||
cat package.json|grep version | ||
- name: Check if there are any changes | ||
id: check-changes-package-json | ||
env: | ||
GH_TOKEN: ${{ steps.app-token.outputs.token }} | ||
IS_CHANGED: ${{ steps.check-changes-fomat-lint.outputs.done-change }} | ||
run: | | ||
git add -N . | ||
OLD_VALUE="${IS_CHANGED}" | ||
if git diff --exit-code --quiet; then | ||
echo "No changes detected." | ||
RESULT="${VAR_NAME_FOR_CHANGED}=${OLD_VALUE}" | ||
else | ||
echo "Changes detected." | ||
git add . | ||
git commit -m "chore: update version of package.json" -m "[AUTO]" | ||
RESULT="${VAR_NAME_FOR_CHANGED}=1" | ||
fi | ||
echo "${RESULT}">>"${GITHUB_OUTPUT}" | ||
echo "${RESULT}" | ||
- name: push | ||
if: ${{ steps.check-changes-package-json.outputs.done-change > 0 }} | ||
env: | ||
GH_TOKEN: ${{ steps.app-token.outputs.token }} | ||
run: git push | ||
|
||
- name: Set the output | ||
id: result | ||
env: | ||
IS_UPDATED: '${{ steps.check-changes-package-json.outputs.done-change }}' | ||
run: | | ||
RESULT="is-updated=${IS_UPDATED}" | ||
echo "${RESULT}">>"${GITHUB_OUTPUT}" | ||
echo "${RESULT}" | ||
lint-pr: | ||
name: Validate PR title | ||
runs-on: ubuntu-latest | ||
permissions: | ||
pull-requests: write | ||
steps: | ||
- uses: amannn/action-semantic-pull-request@v5 | ||
id: lint_pr_title | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- uses: marocchino/sticky-pull-request-comment@v2 | ||
# When the previous steps fails, the workflow would stop. By adding this | ||
# condition you can continue the execution with the populated error message. | ||
if: always() && (steps.lint_pr_title.outputs.error_message != null) | ||
with: | ||
header: pr-title-lint-error | ||
message: | | ||
Hey there and thank you for opening this pull request! 👋🏼 | ||
We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted. | ||
Details: | ||
``` | ||
${{ steps.lint_pr_title.outputs.error_message }} | ||
``` | ||
# Delete a previous comment when the issue has been resolved | ||
- if: ${{ steps.lint_pr_title.outputs.error_message == null }} | ||
uses: marocchino/sticky-pull-request-comment@v2 | ||
with: | ||
header: pr-title-lint-error | ||
delete: true |
Oops, something went wrong.