Merge pull request #375 from traPtitech/fix/publish #774
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: automatic update | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
jobs: | |
release: | |
name: release | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: setup Node | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: "package.json" | |
cache: "npm" | |
registry-url: "https://registry.npmjs.org" | |
- name: npm ci | |
run: npm ci | |
- name: build | |
run: npm run build | |
- name: Check diff | |
run: | | |
OLD_SHASUM=`npm view | grep -oP "(?<=^\.shasum: ).+(?=$)" | sed "s/$(echo -e '\e')\[[0-9][0-9]m//g"` | |
NEW_SHASUM=`npm pack --dry-run 2>&1 >/dev/null | grep -oP "(?<=shasum: ).+(?=$)" | sed "s/^ *//"` | |
echo "OLD: ${OLD_SHASUM}" | |
echo "NEW: ${NEW_SHASUM}" | |
if [ $OLD_SHASUM = $NEW_SHASUM ]; then | |
echo "HAS_DIFF=false" >> $GITHUB_ENV | |
else | |
echo "HAS_DIFF=true" >> $GITHUB_ENV | |
fi | |
- name: Set version name | |
if: env.HAS_DIFF == 'true' | |
run: | | |
TRAQ_VERSION=$(curl -sS https://api.github.com/repos/traPtitech/traQ/tags | jq '.[0].name' | sed -n s/[\"v]//pg) | |
echo "TRAQ ${TRAQ_VERSION}" | |
VERSION=$(cat ./package.json | jq .version | sed -n s/\"//pg | sed -n s/-/./p) | |
echo "PACKAGE ${VERSION}" | |
VERSION_ARR=($(echo $VERSION | tr -s '.' ' ')) | |
VERSION_SHORT=${VERSION_ARR[0]}.${VERSION_ARR[1]}.${VERSION_ARR[2]} | |
echo "PACKAGE SHORT ${VERSION_SHORT}" | |
if [ $TRAQ_VERSION = $VERSION_SHORT ]; then | |
let VERSION_ARR[3]++ 1 | |
NEW_VERSION="${VERSION_ARR[0]}.${VERSION_ARR[1]}.${VERSION_ARR[2]}-${VERSION_ARR[3]}" | |
else | |
NEW_VERSION="${TRAQ_VERSION}-0" | |
fi | |
echo "PACKAGE NEW ${NEW_VERSION}" | |
echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV | |
- name: npm version & publish | |
if: env.HAS_DIFF == 'true' | |
run: | | |
git config user.name "GitHub Actions" | |
git config user.email "actions@github.com" | |
npm version $NEW_VERSION -m "CI: update to $NEW_VERSION [ci skip]" | |
git commit --amend --no-edit --author . | |
git push origin master | |
git push --tags | |
npm publish --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
NEW_VERSION: ${{ env.NEW_VERSION }} |