diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index 1e686f3..3794be1 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -1,39 +1,62 @@ -name: Create Release Branch +# github action name +name: Auto Publish - patch update + +# develop 브랜치에 push 되면 자동 patch update를 한다는 구현 on: - workflow_dispatch: - inputs: - version: - type: choice - description: Sematic version type of new version - options: - - patch - - minor - - major + push: + branches: [ develop ] + +# 실제 실행 구현부 jobs: - release: + # build 환경 + build: runs-on: ubuntu-latest - + permissions: + contents: write + strategy: + matrix: + node-version: [16.13.1] + # 실행할 순서 steps: - - uses: actions/checkout@v3 - with: - ref: develop - - name: Git configuration - run: | - git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" - git config --global user.name "${GITHUB_ACTOR}" - - name: Upgrade version - run: | - yarn --no-git-tag-version version --$RELEASE_TYPE - echo "NEW_VERSION=$(npm pkg get version | tr -d '"')" >> $GITHUB_ENV - env: - RELEASE_TYPE: ${{ github.event.inputs.version }} - - name: Create release branch - run: | - git checkout -b release/${{ env.NEW_VERSION }} - git add "package.json" - git commit -m "Upgrade version to ${{ env.NEW_VERSION }}" - git push origin release/${{ env.NEW_VERSION }} - gh pr create -B main -H release/${{ env.NEW_VERSION }} -d --title 'Upgrade version to ${{ env.NEW_VERSION }}' --body 'Upgrade version to ${{ env.NEW_VERSION }}' - gh pr create -B develop -H release/${{ env.NEW_VERSION }} -d --title 'Release/${{ env.NEW_VERSION }} -> develop' --body 'Upgrade version to ${{ env.NEW_VERSION }}' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # github action에서 NodeJS 세팅을 위한 actions/setup-node@v2 action을 사용 + - uses: actions/checkout@v2 + - name: Set up NodeJS ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + registry-url: https://registry.npmjs.org/ + # yarn을 사용하기에 yarn을 global install하고 install dependencies + - name : Install Dependencies + run: | + npm install -g yarn + npm install --legacy-peer-deps --save-dev --ignore-scripts install-peers + yarn install + # npm version을 patch 명령어를 통해 올리고, 리눅스 파이프라인 명령어를 통해 patch로 변경한 버전을 저장 + - name : Patch + run: | + npm version patch > version.txt + # 저장한 버전 파일을 읽어 변수로 사용하기 위해 외부 action을 사용 -> setps.{id}.outputs.content로 사용 가능 + - name: Read version.txt + id: commit + uses: juliangruber/read-file-action@v1 + with: + path: ./version.txt + # version을 변경한 package.json을 commit, 바뀐 버전으로 commit message 작성 후 push + - name: Deploy and Push + run: | + git config --global user.name "${GITHUB_ACTOR}" + git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" + git add package.json + git commit -m "${{ (steps.commit.outputs.content) }}" + echo ${{ (steps.commit.outputs.content) }} + yarn deploy + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + # slack 웹훅을 통해 채널에 전송 + - name: Send result to slack + uses: Ilshidur/action-slack@2.0.2 + with: + args: "버전 ➡️${{ (steps.commit.outputs.content) }}의 결과는 ➡️${{ job.status }} 에요" + env: + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_URL }} + if: always()