Skip to content

feat: Expose bump level as output #50

feat: Expose bump level as output

feat: Expose bump level as output #50

name: Build & Test
on:
pull_request:
branches:
- main
types:
- opened
- synchronize
- reopened
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
build-dist:
runs-on: [ubuntu-latest]
permissions:
contents: write
pull-requests: write
outputs:
committed_sha: ${{ steps.commit_dist.outputs.commit_sha }}
steps:
- name: Checkout PR head
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.head_ref || github.ref_name }}
token: ${{ secrets.GITHUB_TOKEN}}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20 # use stable LTS; previous 24 caused manifest warning
check-latest: true
- name: Install dependencies
working-directory: .github/actions/core
run: npm ci
- name: Run tests
working-directory: .github/actions/core
run: npm run test
- name: Build action
working-directory: .github/actions/core
run: npm run build
- name: Commit build artifacts (same-repo PRs only)
if: github.event.pull_request.head.repo.full_name == github.repository
id: commit_dist
uses: EndBug/add-and-commit@v9
with:
add: "."
message: "chore: build core action dist (auto)"
default_author: github_actions
push: true
- name: Fail if dist is dirty (Forked PRs only)
if: github.event.pull_request.head.repo.full_name != github.repository
working-directory: .github/actions/core
run: |
if [[ -n $(git status --porcelain dist) ]]; then
echo "::error::The 'dist' folder is out of sync with the source code."
echo "::error::Because this is a forked PR, we cannot automatically commit the changes."
echo "::error::Please run 'npm run build' in '.github/actions/core' locally and commit the changes."
exit 1
fi
test-python:
needs: build-dist
runs-on: [ubuntu-latest]
permissions:
contents: write
pull-requests: read
steps:
- uses: actions/checkout@v4
- name: Patch composite actions for E2E
run: |
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/core@[^[:space:]"]+|./.github/actions/core|g' .github/actions/version-bumping/*/action.yml
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/version-bumping/python@[^[:space:]"]+|./.github/actions/version-bumping/python|g' action.yml
- name: Test Python Action (Dry Run)
id: version_bump
uses: ./
with:
type: python
token: ${{ secrets.GITHUB_TOKEN }}
pyproject-file: "test-resources/pyproject.toml"
dry-run: "true"
- name: Verify Outputs
run: |
echo "Bumped: ${{ steps.version_bump.outputs.bumped }}"
echo "New Version: ${{ steps.version_bump.outputs.new-version }}"
echo "### Python Test New Version: ${{ steps.version_bump.outputs.new-version }}" >> $GITHUB_STEP_SUMMARY
if [ -z "${{ steps.version_bump.outputs.bumped }}" ]; then
echo "Error: 'bumped' output is empty"
exit 1
fi
test-npm:
needs: build-dist
runs-on: [ubuntu-latest]
permissions:
contents: write
pull-requests: read
steps:
- uses: actions/checkout@v4
- name: Patch composite actions for E2E
run: |
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/core@[^[:space:]"]+|./.github/actions/core|g' .github/actions/version-bumping/*/action.yml
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/version-bumping/npm@[^[:space:]"]+|./.github/actions/version-bumping/npm|g' action.yml
- name: Test NPM Action (Dry Run)
id: version_bump
uses: ./
with:
type: npm
token: ${{ secrets.GITHUB_TOKEN }}
package-json-file: "test-resources/package.json"
dry-run: "true"
- name: Verify Outputs
run: |
echo "Bumped: ${{ steps.version_bump.outputs.bumped }}"
echo "New Version: ${{ steps.version_bump.outputs.new-version }}"
echo "### NPM Test New Version: ${{ steps.version_bump.outputs.new-version }}" >> $GITHUB_STEP_SUMMARY
if [ -z "${{ steps.version_bump.outputs.bumped }}" ]; then
echo "Error: 'bumped' output is empty"
exit 1
fi
test-maven:
needs: build-dist
runs-on: [ubuntu-latest]
permissions:
contents: write
pull-requests: read
steps:
- uses: actions/checkout@v4
- name: Patch composite actions for E2E
run: |
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/core@[^[:space:]"]+|./.github/actions/core|g' .github/actions/version-bumping/*/action.yml
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/version-bumping/maven@[^[:space:]"]+|./.github/actions/version-bumping/maven|g' action.yml
- name: Test Maven Action (Dry Run)
id: version_bump
uses: ./
with:
type: maven
token: ${{ secrets.GITHUB_TOKEN }}
dry-run: "true"
pom-file: "test-resources/pom.xml"
# removed actual settings.xml to avoid fetch setting in this simple test
bump-command: "mvn org.codehaus.mojo:versions-maven-plugin:set -DnewVersion=@NEW_VERSION@"
- name: Verify Outputs
run: |
echo "Bumped: ${{ steps.version_bump.outputs.bumped }}"
echo "New Version: ${{ steps.version_bump.outputs.new-version }}"
echo "### Maven Test New Version: ${{ steps.version_bump.outputs.new-version }}" >> $GITHUB_STEP_SUMMARY
if [ -z "${{ steps.version_bump.outputs.bumped }}" ]; then
echo "Error: 'bumped' output is empty"
exit 1
fi
test-version-file:
needs: build-dist
runs-on: [ubuntu-latest]
permissions:
contents: write
pull-requests: read
steps:
- uses: actions/checkout@v4
- name: Patch composite actions for E2E
run: |
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/core@[^[:space:]"]+|./.github/actions/core|g' .github/actions/version-bumping/*/action.yml
sed -i -E 's|sap/pull-request-semver-bumper/.github/actions/version-bumping/version-file@[^[:space:]"]+|./.github/actions/version-bumping/version-file|g' action.yml
- name: Test Version File Action (Dry Run)
id: version_bump
uses: ./
with:
type: version-file
token: ${{ secrets.GITHUB_TOKEN }}
version-file: "test-resources/VERSION"
dry-run: "true"
- name: Verify Outputs
run: |
echo "Bumped: ${{ steps.version_bump.outputs.bumped }}"
echo "New Version: ${{ steps.version_bump.outputs.new-version }}"
echo "### Version File Test New Version: ${{ steps.version_bump.outputs.new-version }}" >> $GITHUB_STEP_SUMMARY
if [ -z "${{ steps.version_bump.outputs.bumped }}" ]; then
echo "Error: 'bumped' output is empty"
exit 1
fi
all-tests-passed:
if: always()
needs: [build-dist, test-python, test-npm, test-maven, test-version-file]
runs-on: ubuntu-latest
permissions:
statuses: write
steps:
- name: Determine Status
id: status
run: |
if [[ ${{ contains(needs.*.result, 'failure') }} == 'true' || ${{ contains(needs.*.result, 'cancelled') }} == 'true' ]]; then
echo "status=failure" >> $GITHUB_OUTPUT
else
echo "status=success" >> $GITHUB_OUTPUT
fi
- name: Set Commit Status
uses: myrotvorets/set-commit-status-action@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ steps.status.outputs.status }}
sha: ${{ needs.build-dist.outputs.committed_sha || github.event.pull_request.head.sha }}
context: "all-tests-passed"
description: "Aggregation of all tests"
- name: Fail if needed
if: steps.status.outputs.status == 'failure'
run: exit 1