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

CI GitHub Actions for United Storage #18

Merged
merged 3 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
57 changes: 57 additions & 0 deletions .github/workflows/build_application_docker.yaml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract tags for Docker
id: meta
uses: docker/[email protected]
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/[email protected]
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
23 changes: 23 additions & 0 deletions .github/workflows/lint_typecheck_unit.yaml
Original file line number Diff line number Diff line change
@@ -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
78 changes: 78 additions & 0 deletions .github/workflows/publish_platform.yaml
Original file line number Diff line number Diff line change
@@ -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"
60 changes: 60 additions & 0 deletions .github/workflows/publish_platform_hotfix.yaml
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 11 additions & 3 deletions scripts/setup-dev-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';

const path = require('path');
const {readFileSync, writeFileSync} = require('fs');
const {readFileSync, writeFileSync, openSync} = require('fs');

const SECRETS_SECTION_START = '### TEMPLATE SECRETS BEGIN';
const SECRETS_SECTION_END = '### TEMPLATE SECRETS END';
Expand All @@ -16,6 +16,7 @@ const appPath = path.join(__dirname, '..');
const templateFilePath = path.join(appPath, `dev/env/${templateName}`);

let templateContent = readFileSync(templateFilePath).toString();
const secretsSection = `${SECRETS_SECTION_START}\n${templateContent}\n${SECRETS_SECTION_END}`;

if (envName === 'development') {
try {
Expand All @@ -28,7 +29,14 @@ if (envName === 'development') {
}
}

const secretsSection = `${SECRETS_SECTION_START}\n${templateContent}\n${SECRETS_SECTION_END}`;
let currentEnv;

try {
currentEnv = readFileSync(path.join(appPath, '.env')).toString();
} catch (__) {
openSync(path.join(appPath, '.env'), 'w');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to open file .env?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied from datalens-ui repo, i gues for creating empty file

Copy link
Collaborator

@jhoncool jhoncool Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's strange, because below writeFileSync have called with default flag w


currentEnv = `${SECRETS_SECTION_START}\n${SECRETS_SECTION_END}`;
}

const currentEnv = readFileSync(path.join(appPath, '.env')).toString();
writeFileSync(path.join(appPath, '.env'), currentEnv.replace(REPLACE_REGEXP, secretsSection));
Loading