Skip to content

Commit

Permalink
ci: Fix release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed Jan 1, 2020
1 parent 11dc2f5 commit 314c9a4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 95 deletions.
71 changes: 4 additions & 67 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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}"
45 changes: 17 additions & 28 deletions release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

0 comments on commit 314c9a4

Please sign in to comment.