[bot] release v1.0.78 (#131) #88
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: release | |
on: | |
push: | |
branches: | |
- main | |
# enforce single job concurrency since we need to push commits | |
concurrency: | |
group: localization-release | |
cancel-in-progress: false | |
env: | |
GIT_AUTHOR_NAME: github-actions[bot] | |
GIT_COMMITTER_NAME: github-actions[bot] | |
GIT_AUTHOR_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com | |
GIT_COMMITTER_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
fetch-tags: true | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
registry-url: "https://npm.pkg.github.com" | |
scope: "@superthread-com" | |
- name: Get current release details | |
id: details | |
continue-on-error: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
CM: ${{ github.event.head_commit.message }} | |
run: | | |
tag=$(gh release view --json tagName --jq '.tagName' || echo "v0.0.0") | |
echo "CURRENT_VERSION=$tag" >> $GITHUB_ENV | |
current_commit=${{ github.sha }} | |
release_commit=$(git rev-list -n 1 "$tag" || echo "0000000000000000000000000000000000000000") | |
if [ "$current_commit" = "$release_commit" ]; | |
then | |
echo "skip=true" >> $GITHUB_OUTPUT | |
fi | |
COMMIT_MESSAGE=$(printf '%q' "$CM") | |
SANITIZED_MSG=$(echo "$COMMIT_MESSAGE" | sed 's/[\`\$&|;<>\\]//g') | |
if echo "$SANITIZED_MSG" | grep -q -E '\[SKIP\]'; | |
then | |
echo "skip=true" >> $GITHUB_OUTPUT | |
fi | |
echo "COMMIT_MSG=$SANITIZED_MSG" >> $GITHUB_ENV | |
- name: Determine change type | |
continue-on-error: true | |
if: ${{ steps.details.outputs.skip != 'true' }} | |
run: | | |
if echo "$COMMIT_MSG" | grep -q -E '\[MAJOR\]'; | |
then | |
CHANGE_TYPE="major" | |
elif echo "$COMMIT_MSG" | grep -q -E '\[MINOR\]'; | |
then | |
CHANGE_TYPE="minor" | |
else | |
CHANGE_TYPE="patch" | |
fi | |
echo "CHANGE_TYPE=$CHANGE_TYPE" >> $GITHUB_ENV | |
- name: Determine new version | |
if: ${{ steps.details.outputs.skip != 'true' }} | |
run: | | |
LATEST=${CURRENT_VERSION:-"0.0.0"} | |
VERSION="${LATEST#v}" | |
IFS='.' read -r -a semver <<< "$VERSION" | |
major=${semver[0]} | |
minor=${semver[1]} | |
patch=${semver[2]} | |
if [[ "$CHANGE_TYPE" == "major" ]]; then | |
major=$((major + 1)) | |
minor=0 | |
patch=0 | |
elif [[ "$CHANGE_TYPE" == "minor" ]]; then | |
minor=$((minor + 1)) | |
patch=0 | |
else | |
patch=$((patch + 1)) | |
fi | |
NEW_VERSION="v$major.$minor.$patch" | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
- name: Create GitHub Release | |
if: ${{ steps.details.outputs.skip != 'true' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: gh release create "$NEW_VERSION" --title="$NEW_VERSION" --generate-notes | |
- name: Create NPM release | |
if: ${{ steps.details.outputs.skip != 'true' }} | |
run: npm version "$NEW_VERSION" --no-git-tag-version | |
- name: Check for modified files | |
if: ${{ steps.details.outputs.skip != 'true' }} | |
id: git | |
run: | | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "modified=true" >> $GITHUB_OUTPUT | |
else | |
echo "modified=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Publish new version | |
id: publish | |
if: ${{ steps.git.outputs.modified == 'true' && steps.details.outputs.skip != 'true'}} | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
npm install --include=dev | |
npm publish | |
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
- name: Create PR | |
if: ${{ steps.git.outputs.modified == 'true' && steps.details.outputs.skip != 'true'}} | |
id: pr | |
env: | |
APP: localization | |
HEAD: release-${{ steps.publish.outputs.version }} | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
VERSION: ${{ steps.publish.outputs.version }} | |
run: | | |
git checkout -b $HEAD | |
git add package.json | |
git commit -m "[bot] ts release $APP $NEW_VERSION" | |
git push --set-upstream origin $HEAD | |
url=$(gh pr create \ | |
--title '[bot] release ${{ env.VERSION }}' \ | |
--body 'This PR bumps the version to ${{ env.VERSION }}') | |
echo "URL=$(echo $url)" >> $GITHUB_OUTPUT | |
- name: Merge PR | |
if: ${{ steps.git.outputs.modified == 'true' && steps.details.outputs.skip != 'true'}} | |
env: | |
REPO: ${{ github.repository }} | |
URL: ${{ steps.pr.outputs.URL }} | |
GH_TOKEN: ${{ secrets.GH_ACCESS_TOKEN }} | |
run: gh pr merge "${URL}" --repo "${REPO}" --squash --admin |