From b4b7dd4276928ba54001c26e389d6f6c3637f8b8 Mon Sep 17 00:00:00 2001 From: Georgy Malkov Date: Wed, 25 Oct 2023 11:58:44 +0300 Subject: [PATCH] CI GitHub Actions for United Storage --- .../workflows/build_application_docker.yaml | 57 ++++++++++++++ .github/workflows/lint_typecheck_unit.yaml | 23 ++++++ .github/workflows/publish_platform.yaml | 78 +++++++++++++++++++ .../workflows/publish_platform_hotfix.yaml | 60 ++++++++++++++ 4 files changed, 218 insertions(+) create mode 100644 .github/workflows/build_application_docker.yaml create mode 100644 .github/workflows/lint_typecheck_unit.yaml create mode 100644 .github/workflows/publish_platform.yaml create mode 100644 .github/workflows/publish_platform_hotfix.yaml diff --git a/.github/workflows/build_application_docker.yaml b/.github/workflows/build_application_docker.yaml new file mode 100644 index 00000000..d1f0cbca --- /dev/null +++ b/.github/workflows/build_application_docker.yaml @@ -0,0 +1,57 @@ +on: + workflow_dispatch: + release: + types: [published] + +concurrency: + group: ${{ github.workflow }} + cancel-in-progress: false + +name: Build Application Docker + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + name: datalens-us + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-buildx-action@v3 + - name: 'Get release build version' + run: | + BUILD_VERSION=$(jq -r '.version' package.json) + COMMIT_NAME=$(git log -n 1 --pretty=format:%s) + echo "Release build version: ${BUILD_VERSION}" + echo "BUILD_VERSION=$BUILD_VERSION" >> "$GITHUB_ENV" + echo "COMMIT_NAME=$COMMIT_NAME" >> "$GITHUB_ENV" + - name: Log in to the Container registry + uses: docker/login-action@v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Extract tags for Docker + id: meta + uses: docker/metadata-action@v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=${{ env.BUILD_VERSION }} + ${{ contains(env.COMMIT_NAME, '[release]') && 'type=raw,value=latest' || '' }} + - name: Build and push Docker image + uses: docker/build-push-action@v5.0.0 + with: + build-args: | + app_version=${{ env.BUILD_VERSION }} + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/lint_typecheck_unit.yaml b/.github/workflows/lint_typecheck_unit.yaml new file mode 100644 index 00000000..f136da3a --- /dev/null +++ b/.github/workflows/lint_typecheck_unit.yaml @@ -0,0 +1,23 @@ +on: + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +name: Lint, Typecheck, Unit tests + +jobs: + build: + name: datalens-us + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'npm' + - run: npm ci + - run: npm run lint + - run: npm run typecheck + - run: npm run test diff --git a/.github/workflows/publish_platform.yaml b/.github/workflows/publish_platform.yaml new file mode 100644 index 00000000..65c39fe2 --- /dev/null +++ b/.github/workflows/publish_platform.yaml @@ -0,0 +1,78 @@ +on: + push: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +name: Publish Platform + +permissions: + contents: write + +jobs: + build: + name: datalens-us + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: . + fetch-depth: 0 + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'npm' + - name: 'Get last release' + run: | + COMMIT_NAME=$(git log -n 1 --pretty=format:%s) + + LAST_RELEASE_VERSION=$(curl -L https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq -r '.|=sort_by(.name)|.[-1].name' | sed 's|v||') + echo "Last release version: ${LAST_RELEASE_VERSION}" + + MAIN_COMMIT=$(git rev-parse origin/main) + echo "Main commit: ${MAIN_COMMIT}" + LAST_RELEASE_BRANCH="release-${LAST_RELEASE_VERSION}" + LAST_RELEASE_COMMIT=$(git rev-parse "origin/$LAST_RELEASE_BRANCH") + echo "Last release commit: ${LAST_RELEASE_COMMIT}" + + if [ "$MAIN_COMMIT" = "$LAST_RELEASE_COMMIT" ]; then echo "Hash commit in main branch matches the last release branch commit" && exit 1; fi + + echo "COMMIT_NAME=$COMMIT_NAME" >> "$GITHUB_ENV" + echo "LAST_RELEASE_VERSION=$LAST_RELEASE_VERSION" >> "$GITHUB_ENV" + - name: 'Make new release version number' + run: | + npm version "$LAST_RELEASE_VERSION" --no-git-tag-version --allow-same-version + + TAG_NEW_VERSION=$(npm version minor --no-git-tag-version --allow-same-version) + NEW_VERSION=$(echo $TAG_NEW_VERSION | sed 's|v||') + + echo "NEW_VERSION=$NEW_VERSION" >> "$GITHUB_ENV" + echo "TAG_NEW_VERSION=$TAG_NEW_VERSION" >> "$GITHUB_ENV" + - name: 'Create new release branch' + run: | + NEW_BRANCH="release-$NEW_VERSION" + + git checkout -b "$NEW_BRANCH" + echo "Created new release branch: $NEW_BRANCH" + + echo "NEW_BRANCH=$NEW_BRANCH" >> "$GITHUB_ENV" + - name: 'Commit package version' + run: | + git config user.email "" && git config user.name "GitHub Release" + git add package.json && git add package-lock.json && git commit -am "Bump version to $NEW_VERSION [release]" + git push --set-upstream origin "$NEW_BRANCH" + - uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.TAG_NEW_VERSION }} + release_name: ${{ env.TAG_NEW_VERSION }} + commitish: ${{ env.NEW_BRANCH }} + body: ${{ env.COMMIT_NAME }} + draft: false + prerelease: false + - name: 'Success notify' + run: echo "Version bumped to '$TAG_NEW_VERSION' and pushed to remote repository" diff --git a/.github/workflows/publish_platform_hotfix.yaml b/.github/workflows/publish_platform_hotfix.yaml new file mode 100644 index 00000000..4678058e --- /dev/null +++ b/.github/workflows/publish_platform_hotfix.yaml @@ -0,0 +1,60 @@ +on: + push: + branches: + - 'release-**' + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +name: Publish Platform Hotfix + +permissions: + contents: write + +jobs: + build: + if: "!contains(github.event.commits[0].message, '[hotfix]') && !contains(github.event.commits[0].message, '[release]')" + name: datalens-us + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: . + - uses: actions/setup-node@v3 + with: + node-version: 18 + cache: 'npm' + - name: 'Get current release' + run: | + COMMIT_NAME=$(git log -n 1 --pretty=format:%s) + + RELEASE_BRANCH="$GITHUB_REF_NAME" + RELEASE_VERSION=$(echo $RELEASE_BRANCH | sed 's|release-||') + echo "Release version: ${RELEASE_VERSION}" + + echo "COMMIT_NAME=$COMMIT_NAME" >> "$GITHUB_ENV" + - name: 'Make new release version number' + run: | + TAG_NEW_VERSION=$(npm version patch --no-git-tag-version --allow-same-version) + NEW_VERSION=$(echo $TAG_NEW_VERSION | sed 's|v||') + + echo "NEW_VERSION=$NEW_VERSION" >> "$GITHUB_ENV" + echo "TAG_NEW_VERSION=$TAG_NEW_VERSION" >> "$GITHUB_ENV" + - name: 'Commit package version' + run: | + git config user.email "" && git config user.name "GitHub Release" + git add package.json && git add package-lock.json && git commit -am "Bump version to $NEW_VERSION [hotfix]" + git push + - uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.TAG_NEW_VERSION }} + release_name: ${{ env.TAG_NEW_VERSION }} + commitish: ${{ env.GITHUB_REF_NAME }} + body: ${{ env.COMMIT_NAME }} + draft: false + prerelease: false + - name: 'Success notify' + run: echo "Version bumped to '$TAG_NEW_VERSION' and pushed to remote repository"