Publish package #100
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: Publish package | |
on: | |
create: | |
jobs: | |
release: | |
if: ${{ startsWith(github.ref, 'refs/tags/v') }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
with: | |
fetch-depth: 0 | |
- name: Setup Node.js | |
uses: actions/setup-node@v2 | |
with: | |
node-version: '14.x' | |
- name: Set release version env variables | |
run: | | |
export RELEASE_TAG_VERSION="$(echo "${{ github.ref }}" | grep -oP '(?<=refs/tags/v)\d+\.\d+\.\d+.*')" | |
echo "RELEASE_TAG_VERSION=${RELEASE_TAG_VERSION}" >> $GITHUB_ENV | |
export MAJOR_TAG_VERSION="$(echo ${RELEASE_TAG_VERSION} | grep -oP '^[^.]+').x" | |
echo "MAJOR_TAG_VERSION=${MAJOR_TAG_VERSION}" >> $GITHUB_ENV | |
- name: Ensure new version is mentioned in change log | |
run: grep --regexp "\[v${RELEASE_TAG_VERSION}\]" CHANGELOG.md | |
- name: Extract changelog for release | |
run: awk -v ver=${RELEASE_TAG_VERSION} '/^#+ \[v/ { if (p) { exit }; if ($2 ~ "[v"ver"]") { p=1; next } } p' CHANGELOG.md > release-changelog.md | |
- name: Install dependencies | |
run: yarn install --immutable | |
- name: Lint | |
run: yarn lint | |
- name: Run tests | |
run: yarn test --maxWorkers=2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
- name: Install docs dependencies | |
run: yarn install-docs-deps | |
- name: Clean docs directories | |
run: rm -rf site docs/api | |
- name: Import GPG key | |
uses: crazy-max/ghaction-import-gpg@v4 | |
with: | |
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | |
passphrase: ${{ secrets.GPG_PASS }} | |
git_user_signingkey: true | |
git_commit_gpgsign: true | |
git_tag_gpgsign: true | |
- name: Set aliases | |
run: | | |
export LATEST_DOCS_VERSION="$(mike list | grep -oP '^.+(?= \[latest\])')" | |
if [ -z "$LATEST_DOCS_VERSION" ]; then | |
echo "ALIAS_LATEST=latest" >> $GITHUB_ENV | |
else | |
npx -y semver -r ">$LATEST_DOCS_VERSION" ${RELEASE_TAG_VERSION} | |
if [ $? -eq 0 ]; then | |
echo "ALIAS_LATEST=latest" >> $GITHUB_ENV | |
fi | |
fi | |
export LATEST_DOCS_VERSION_FOR_MAJOR="$(mike list | grep -oP "^.+(?= \[$MAJOR_TAG_VERSION\])")" | |
if [ -z "$LATEST_DOCS_VERSION_FOR_MAJOR" ]; then | |
echo "ALIAS_MAJOR=$MAJOR_TAG_VERSION" >> $GITHUB_ENV | |
else | |
npx -y semver -r "^$LATEST_DOCS_VERSION_FOR_MAJOR" ${RELEASE_TAG_VERSION} | |
if [ $? -eq 0 ]; then | |
echo "ALIAS_MAJOR=$MAJOR_TAG_VERSION" >> $GITHUB_ENV | |
fi | |
fi | |
- name: Build docs | |
run: | | |
yarn build-docs:api | |
mike deploy -u ${RELEASE_TAG_VERSION} ${ALIAS_MAJOR} ${ALIAS_LATEST} | |
mike set-default --push latest | |
env: | |
VERSION: ${{ env.RELEASE_TAG_VERSION }} | |
ALIAS: latest | |
- name: Build package | |
run: yarn pack | |
- name: Create release | |
uses: softprops/action-gh-release@v1 | |
with: | |
body_path: release-changelog.md | |
files: package.tgz | |
- name: Deploy docs | |
run: git push origin gh-pages | |
- name: Publish to registry | |
run: | | |
yarn config set npmAlwaysAuth true | |
yarn config set npmAuthToken ${{ secrets.NPM_TOKEN }} | |
yarn npm publish |