make sure release only creates when labels are right #16
Workflow file for this run
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 and Versioning | |
on: | |
push: | |
branches: | |
- main | |
- fix_yarn_version_cli | |
pull_request_review: | |
types: [submitted] | |
jobs: | |
create-release: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
ref: ${{ github.event.pull_request.head.ref || github.ref_name }} | |
- name: Check last PR labels | |
id: check_labels | |
env: | |
GH_TOKEN: ${{ github.token }} | |
# if: github.event.review.state == 'approved' | |
run: | | |
LAST_PR_NUMBER=$(gh pr list --state merged --json number --jq '.[0].number') | |
LABELS=$(gh pr view "$LAST_PR_NUMBER" --json labels --jq '.labels[].name') | |
echo "::notice::PR used to check version bump: #$LAST_PR_NUMBER" | |
echo "::notice::PR labels: "[${LABELS//$'\n'/,}]"" | |
RELEASE_TYPE=$(./.github/ci-scripts/pr-label-check.sh) || exit_code=$? | |
if [ "$exit_code" -ne 0 ]; then | |
echo "::error::PR #"$LAST_PR_NUMBER" has more than one release label" | |
exit $exit_code | |
fi | |
echo "version=$RELEASE_TYPE" >> $GITHUB_OUTPUT | |
echo "::group::Output version" | |
echo "::notice::Release type: $RELEASE_TYPE" | |
if [ "$RELEASE_TYPE" == "no-release" ]; then | |
echo "::notice::PR is not flagged for release, skipping other steps" | |
fi | |
echo "::endgroup::" | |
- name: Bump version | |
id: bump | |
# if: github.event.review.state == 'approved' && steps.check_labels.outputs.version != 'no-release' | |
run: | | |
git config user.name "GitHub Actions" | |
git config user.email "actions@github.com" | |
if [ "${{ steps.check_labels.outputs.version }}" == "alpha" ]; then | |
npm version -m "[bot] New pkg version: %s" --preid=alpha prerelease | |
else | |
npm version -m "[bot] New pkg version: %s" ${{ steps.check_labels.outputs.version }} | |
fi | |
git push | |
- name: Create GitHub Release | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.check_labels.outputs.version != 'no-release' | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
VERSION=$(node -p "require('./package.json').version") | |
gh release create "v${VERSION}" \ | |
--title "Release v${VERSION}" \ | |
--generate-notes \ | |
--prerelease \ | |
--target "${GITHUB_SHA}" |