Release #50
Workflow file for this run
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
name: Release | |
on: | |
workflow_dispatch: | |
inputs: | |
# Input для ввода features changes (для CHANGELOG.md) | |
features: | |
type: text | |
description: changelog features | |
default: '' | |
# Input для ввода bugfixes changes (для CHANGELOG.md) | |
bugfixes: | |
type: text | |
description: changelog bugfixes | |
default: '' | |
# Input для ввода breaking changes (для CHANGELOG.md) | |
breaking-changes: | |
type: text | |
description: changelog breaking changes | |
default: '' | |
# Select для выбора версии | |
version: | |
type: choice | |
description: Choose which version to release | |
required: true | |
options: | |
- beta | |
- patch | |
- minor | |
- major | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
# Проверка прав доступа. Только пользователь из white_list может выполнить релизную сборку. | |
# Остальные могут только выпустить beta версию пакета. | |
- name: Check permissions | |
run: | | |
white_list=("DavidGuryanov","vahrammer","sashabull66") | |
if [[ "${white_list[@]}" =~ "${ACTOR}" ]] | |
then echo "Доступ разрешен." | |
elif [[ "${SELECTED_VERSION}" == "beta" ]] | |
then echo "Доступ разрешен только для публикации beta версии пакета." | |
else | |
echo "Вы не можете выполнить выпуск $SELECTED_VERSION версии пакета. Доступ запрещен!" | |
exit 1 | |
fi | |
env: | |
SELECTED_VERSION: ${{ github.event.inputs.version }} | |
ACTOR: ${{ github.actor }} | |
# Переключение на выбранную при запуске action ветку и скачивание файлов в окружение. | |
- name: Checkout | |
uses: actions/checkout@v3 | |
# Установка учётных данных bot как gitUser в текущем окружении (для release commit). | |
# Извлечение имени текущей ветки. | |
# Извлечение sha последнего commit из выбранной ветки (нужно для построения версии beta). | |
- name: Git config | |
run: | | |
git config user.name ${{ secrets.BOT_USERNAME }} | |
git config user.email ${{ secrets.BOT_EMAIL }} | |
echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT | |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
id: branch | |
# Установка зависимостей. | |
- name: Install dependencies | |
run: yarn install | |
# Сборка приложения в /.publish. | |
- name: Build app | |
run: yarn build | |
# Установка npm токена для возможности публикации. | |
- name: Set npm token | |
uses: filipstefansson/set-npm-token-action@v1 | |
with: | |
token: ${{ secrets.NPM_TOKEN }} | |
# Публикация выбранной версии в npm. | |
- name: Publish ${{ github.event.inputs.version }} version | |
run: | | |
export TAG="latest" | |
export VERSION="$SELECTED_VERSION" | |
if [[ $SELECTED_VERSION == "beta" ]] | |
then | |
CURRENT_VERSION=$(grep -o '"version": "[^"]*' package.json | awk -F'"' '{print $4}') | |
export TAG="beta" | |
export VERSION="$CURRENT_VERSION-beta-${{ steps.branch.outputs.sha_short }}" | |
fi | |
yarn release | |
if [[ $SELECTED_VERSION == "beta" ]] | |
then | |
echo "### Выпущена новая версия библиотеки: $VERSION" >> $GITHUB_STEP_SUMMARY | |
fi | |
env: | |
BRANCH: ${{ steps.branch.outputs.branch }} | |
SELECTED_VERSION: ${{ github.event.inputs.version }} | |
# Заполнение файла changelog и выполнение release commit && push в релизную ветку. | |
- name: Fill changelog file and create release branch | |
if: github.event.inputs.version != 'beta' | |
id: changelog | |
run: | | |
export VERSION=$(grep -o '"version": "[^"]*' package.json | awk -F'"' '{print $4}') | |
export RELEASE_BRANCH="release-$VERSION" | |
export MESSAGE="Релиз версии $VERSION" | |
echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> $GITHUB_OUTPUT | |
echo "MESSAGE=$MESSAGE" >> $GITHUB_OUTPUT | |
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT | |
yarn changelog | |
git checkout -b "$RELEASE_BRANCH" | |
git commit -m "$MESSAGE" package.json CHANGELOG.md | |
git push --set-upstream origin "$RELEASE_BRANCH" | |
env: | |
BRANCH: ${{ steps.branch.outputs.branch }} | |
LAST_COMMIT_URL: https://github.com/${{ github.repository }}/commit/${{ steps.branch.outputs.sha_short }} | |
SHA_SHORT: ${{ steps.branch.outputs.sha_short }} | |
SEMANTIC_VERSION: ${{ github.event.inputs.version }} | |
FEATURES: ${{ github.event.inputs.features }} | |
BUGFIXES: ${{ github.event.inputs.bugfixes }} | |
BREAKING_CHANGES: ${{ github.event.inputs.breaking-changes }} | |
BOT_TOKEN: ${{ secrets.BOT_AUTH_TOKEN }} | |
REPOSITORY: ${{ github.repository }} | |
# Создание pull request из релизной ветки в целевую. | |
- name: Create release pull request from ${{ steps.changelog.outputs.RELEASE_BRANCH }} to ${{ steps.branch.outputs.branch }} | |
if: github.event.inputs.version != 'beta' | |
run: | | |
curl --user "$BOT_USERNAME:$BOT_TOKEN" \ | |
--request POST \ | |
--url "https://api.github.com/repos/$REPOSITORY/pulls" \ | |
--header "content-type: application/json" \ | |
--data "{ | |
\"title\": \"$TITLE\", | |
\"head\": \"$HEAD\", | |
\"base\": \"$BASE\", | |
\"body\": \"$BODY\" | |
}" | |
env: | |
BOT_USERNAME: ${{ secrets.BOT_USERNAME }} | |
REPOSITORY: ${{ github.repository }} | |
BOT_TOKEN: ${{ secrets.GH_TOKEN }} | |
TITLE: ${{ steps.changelog.outputs.MESSAGE }} | |
BODY: Этот PR создан автоматически, после публикации версии ${{ steps.changelog.outputs.VERSION }} библиотеки в npm. | |
HEAD: ${{ steps.changelog.outputs.RELEASE_BRANCH }} | |
BASE: ${{ steps.branch.outputs.branch }} |