Skip to content

publish

publish #26

Workflow file for this run

## This workflow has been disabled for now, because the CKAN API is blocking our requests.
## Re-enable when we can package test data inside this repository.
name: "publish"
on:
workflow_run:
workflows: ["tests"]
types:
- completed
workflow_dispatch:
jobs:
publish:
if: ${{ github.event.pull_request == null || github.event.pull_request.draft == false }}
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
#
# package.json に変化がなければ、node_modulesのキャッシュをrestoreする。
# jobが終了すると自動的にキャッシュされる
#
- uses: actions/cache@v4
name: Setup npm cache
id: node_modules
with:
path: |
node_modules/
key: ${{ github.head_ref }}-npm-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ github.head_ref }}-npm-${{ hashFiles('**/package.json') }}
#
# node_modules のキャッシュキーがヒットしていなければ
# package.json に従ってインストールする
#
- name: Install dependencies
if: steps.node_modules.outputs.cache-hit != 'true'
run: |
npm install --global yarn
yarn install
#
# src以下のファイルが変化していなければ、buildをrestoreする
#
- uses: actions/cache@v4
name: build_cache
id: build_cache
with:
path: |
build/
key: ${{ github.head_ref }}-build-${{ hashFiles('src/**/*.ts') }}
restore-keys: |
${{ github.head_ref }}-build-${{ hashFiles('src/**/*.ts') }}
#
# ビルドのキャッシュがなければビルド
#
- name: Install dependencies
if: steps.build_cache.outputs.cache-hit != 'true'
run: |
npm run build
- name: Get the latest commit ID
id: commit
run: echo "commit_id=$(git rev-parse HEAD)" >> $GITHUB_ENV
- name: create changelog.md
id: prepare
run: |
version=$(cat package.json | jq -r '.version')
echo "version=$version" >> $GITHUB_OUTPUT
tgz=$(npm pack | tail -n1 | tr -d '\n')
echo "tgz=$tgz" >> $GITHUB_OUTPUT
#
# pull_requestの場合は、npm publish . --dry-run
# workflow_dispatch(手動)の場合は、npm publish .
#
- name: npm release (trigger / workflow_dispatch)
run: |
if [ "${GITHUB_EVENT_NAME}" = "pull_request" ]; then
npm publish . --dry-run
gh release create ${{ steps.prepare.outputs.version }}-${{ env.commit_id }} ${{ steps.prepare.outputs.tgz }}
elif [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then
gh release create ${{ steps.prepare.outputs.version }} ${{ steps.prepare.outputs.tgz }}
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
npm publish . --access public
fi
env:
# GH_TOKEN: ${{ secrets.G_ACTIONS_TOKEN_FOR_PR }}
GITHUB_TOKEN: ${{ secrets.G_ACTIONS_TOKEN_FOR_PR }}