From 314c9a4ecbbe1251e1bb17335ea141e153d2f863 Mon Sep 17 00:00:00 2001 From: peaceiris <30958501+peaceiris@users.noreply.github.com> Date: Wed, 1 Jan 2020 17:48:04 +0900 Subject: [PATCH] ci: Fix release workflow --- .github/workflows/release.yml | 71 ++--------------------------------- release.sh | 45 +++++++++------------- 2 files changed, 21 insertions(+), 95 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0522019..9328815 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,13 +2,12 @@ name: Release on: push: - branches: - - 'release-*' + tags: + - 'v*.*.*' jobs: release: runs-on: ubuntu-18.04 - if: github.event.before == '0000000000000000000000000000000000000000' steps: - uses: actions/checkout@v2 @@ -18,56 +17,6 @@ jobs: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "${GITHUB_CONTEXT}" - - name: Set release env - run: | - BRANCH_NAME="${GITHUB_REF#refs/heads/}" - RELEASE_TYPE="${BRANCH_NAME#release-}" - echo "::set-env name=BRANCH_NAME::${BRANCH_NAME}" - echo "::set-env name=RELEASE_TYPE::${RELEASE_TYPE}" - - - name: Read .nvmrc - run: echo "::set-output name=NVMRC::$(cat .nvmrc)" - id: nvm - - - name: Setup Node - uses: actions/setup-node@v1 - with: - node-version: "${{ steps.nvm.outputs.NVMRC }}" - - - run: npm ci - - - name: Setup Git - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" - git config user.name "${GITHUB_ACTOR}" - git config user.email "${GITHUB_ACTOR}@users.noreply.github.com" - - - name: Commit build assets - run: | - mkdir ./lib - npm run build - git add ./lib/index.js - git commit -m "ci: Add build assets" - - - name: Prepare release - run: | - echo "::set-env name=CHANGELOG_SHA::$(git rev-parse HEAD)" - git fetch origin - npm run release -- --release-as "${RELEASE_TYPE}" --preset eslint - git push origin "${BRANCH_NAME}" - export TAG_NAME="v$(jq -r '.version' ./package.json)" - git push origin "${TAG_NAME}" - echo "::set-env name=TAG_NAME::${TAG_NAME}" - - - name: Remove build assets - run: | - git rm ./lib/index.js - rm -rf ./lib - git commit -m "ci: Remove build assets" - git push origin "${BRANCH_NAME}" - - name: Install hub run: | HUB_VERSION="2.13.0" @@ -84,23 +33,11 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - git diff "${CHANGELOG_SHA}" HEAD ./CHANGELOG.md | grep "^+" | sed -e '1d' | sed -e 's/^+//g' > ./release_notes.md + TAG_NAME="${GITHUB_REF##refs/tags/}" + git log -n 1 -p ./CHANGELOG.md | grep "^+" | sed -e '1d' | sed -e 's/^+//g' > ./release_notes.md sed -i "1iRelease ${TAG_NAME}\n" ./release_notes.md hub release create \ --draft \ --prerelease \ --file ./release_notes.md \ "${TAG_NAME}" - - - name: Open Pull Request - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - BASE_REF="${{ github.event.base_ref }}" - BASE_BRANCH="${BASE_REF#refs/heads/}" - USER_ID="${GITHUB_REPOSITORY%/*}" - hub pull-request \ - --draft \ - --base "${USER_ID}:${BASE_BRANCH}" \ - --head ${USER_ID}:"${BRANCH_NAME}" \ - --message "Release ${TAG_NAME}" diff --git a/release.sh b/release.sh index f38d57a..929e967 100755 --- a/release.sh +++ b/release.sh @@ -3,37 +3,26 @@ # fail on unset variables and command errors set -eu -o pipefail # -x: is for debugging -BASE_BRANCH="$(git branch --show-current)" - -echo "Base branch is ${BASE_BRANCH}, continue? (y/n)" -read -r res -if [ "${res}" = "n" ]; then - echo "Stop script" - exit 0 +if [ "$(git branch --show-current)" != "master" ]; then + echo "Current branch is not master" 1>&2 + exit 1 fi -RELEASE_TYPE_LIST="major minor patch premajor preminor prepatch prerelease" - -if command -v fzf; then - RELEASE_TYPE=$(echo "${RELEASE_TYPE_LIST}" | tr ' ' '\n' | fzf --layout=reverse) -else - select sel in ${RELEASE_TYPE_LIST}; do - RELEASE_TYPE="${sel}" - break - done -fi +git fetch origin +git pull origin master +git pull origin --tags -echo "Create ${RELEASE_TYPE} release" -RELEASE_BRANCH="release-${RELEASE_TYPE}" -echo "Release branch is ${RELEASE_BRANCH}" +mkdir ./lib +npm run build +git add ./lib/index.js +git commit -m "chore(release): Add build assets" -git fetch origin -git push origin "${BASE_BRANCH}" -git pull origin "${BASE_BRANCH}" +npm run release --preset eslint -if ! git branch "${RELEASE_BRANCH}"; then - exit 1 -fi +git rm ./lib/index.js +rm -rf ./lib +git commit -m "chore(release): Remove build assets" -git checkout "${RELEASE_BRANCH}" -git push origin "${RELEASE_BRANCH}" +TAG_NAME="v$(jq -r '.version' ./package.json)" +git push origin master +git push origin "${TAG_NAME}"