# .github/workflows/semantic-release.yml name: Semantic Release on: workflow_run: workflows: - Release Trigger types: - completed permissions: contents: write issues: write pull-requests: write jobs: release: if: github.event.workflow_run.conclusion == 'success' runs-on: ubuntu-latest steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up Node.js uses: actions/setup-node@v3 with: node-version: "20" - name: Install dependencies run: npm ci - name: Run tests run: npm test - name: Run Semantic Release id: semantic_release env: GITHUB_TOKEN: ${{ secrets.GH_RELEASE_PAT }} run: | set +e OUTPUT=$(npx semantic-release 2>&1) STATUS=$? echo "$OUTPUT" | tee /dev/stderr if [[ $STATUS -eq 0 ]]; then # Extract release tag RELEASE_TAG=$(echo "$OUTPUT" | grep -oP '(?<=next release version is )[^ ]+') echo "RELEASE_TAG=${RELEASE_TAG}" >> $GITHUB_ENV exit 0 elif [[ $STATUS -eq 1 && "$OUTPUT" == *"There are no relevant changes"* ]]; then echo "No release needed. semantic-release exited cleanly." exit 0 else echo "❌ semantic-release failed with unexpected error (exit $STATUS)." exit $STATUS fi