import { Toolkit } from 'actions-toolkit' ; import semver from 'semver' ; import createOrUpdateRef from './create-or-update-ref' ; import createCommit from './create-commit' ; import updateTag from './update-tag' ; import getTagName from './get-tag-name' ; export default async function buildAndTagAction ( tools ) { const tagName = getTagName ( tools ) ; tools . log . info ( `Updating tag [${ tagName }]` ) ; const commit = await createCommit ( tools ) ; await updateTag ( tools , commit . sha , tagName ) ; let shouldRewriteMajorAndMinorRef = true ; if ( tools . context . event === 'release' ) { const { draft , prerelease } = tools . context . payload . release ; if ( draft || prerelease ) { shouldRewriteMajorAndMinorRef = false ; } } if ( shouldRewriteMajorAndMinorRef ) { const majorStr = semver . major ( tagName ) . toString ( ) ; const minorStr = semver . minor ( tagName ) . toString ( ) ; await createOrUpdateRef ( tools , commit . sha , `${ majorStr }.${ minorStr }` ) ; return createOrUpdateRef ( tools , commit . sha , majorStr ) ; } }