[INFRA] Set up default rulesets for default and release branches #740
This file contains hidden or 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
| # This workflow will build a Java project with Maven | |
| # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven | |
| name: build | |
| on: | |
| push: | |
| branches: | |
| - master | |
| pull_request: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v2 | |
| with: | |
| fetch-depth: '0' | |
| - name: Set up JDK 1.8 | |
| uses: actions/setup-java@v1 | |
| with: | |
| java-version: 1.8 | |
| - name: Build with Maven | |
| run: mvn clean test cobertura:cobertura | |
| - name: Codecov | |
| uses: codecov/codecov-action@v1 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| prepare_snapshot_version: | |
| name: Prepare Snapshot Version | |
| needs: build | |
| if: ${{ github.repository == 'apache/casbin-jcasbin' && github.event_name == 'push' && github.ref == 'refs/heads/master' }} | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.snapshot.outputs.version }} | |
| maven_version: ${{ steps.snapshot.outputs.maven_version }} | |
| basename: ${{ steps.snapshot.outputs.basename }} | |
| previous_tag: ${{ steps.snapshot.outputs.previous_tag }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Compute snapshot version | |
| id: snapshot | |
| run: | | |
| LATEST_RELEASE_TAG="$( | |
| git tag --list 'v*' | | |
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | | |
| sort -V | | |
| tail -n 1 | |
| )" | |
| if [ -z "${LATEST_RELEASE_TAG}" ]; then | |
| BASE_VERSION="0.1.0" | |
| else | |
| RELEASE_VERSION="${LATEST_RELEASE_TAG#v}" | |
| MAJOR="${RELEASE_VERSION%%.*}" | |
| REST="${RELEASE_VERSION#*.}" | |
| MINOR="${REST%%.*}" | |
| NEXT_MINOR="$((MINOR + 1))" | |
| BASE_VERSION="${MAJOR}.${NEXT_MINOR}.0" | |
| fi | |
| ESCAPED_BASE_VERSION="${BASE_VERSION//./\\.}" | |
| LAST_SNAPSHOT_NUMBER="$( | |
| git tag --list "v${BASE_VERSION}-snapshot.*" | | |
| sed -nE "s/^v${ESCAPED_BASE_VERSION}-snapshot\\.([0-9]+)$/\\1/p" | | |
| sort -n | | |
| tail -n 1 | |
| )" | |
| LAST_SNAPSHOT_NUMBER="${LAST_SNAPSHOT_NUMBER:-0}" | |
| NEXT_SNAPSHOT_NUMBER="$((LAST_SNAPSHOT_NUMBER + 1))" | |
| SNAPSHOT_VERSION="v${BASE_VERSION}-snapshot.${NEXT_SNAPSHOT_NUMBER}" | |
| MAVEN_VERSION="${SNAPSHOT_VERSION#v}" | |
| BASENAME="jcasbin-${MAVEN_VERSION}-src" | |
| echo "version=${SNAPSHOT_VERSION}" >> "${GITHUB_OUTPUT}" | |
| echo "maven_version=${MAVEN_VERSION}" >> "${GITHUB_OUTPUT}" | |
| echo "basename=${BASENAME}" >> "${GITHUB_OUTPUT}" | |
| if [ "${LAST_SNAPSHOT_NUMBER}" -gt 0 ]; then | |
| echo "previous_tag=v${BASE_VERSION}-snapshot.${LAST_SNAPSHOT_NUMBER}" >> "${GITHUB_OUTPUT}" | |
| else | |
| echo "previous_tag=${LATEST_RELEASE_TAG}" >> "${GITHUB_OUTPUT}" | |
| fi | |
| echo "Computed snapshot version: ${SNAPSHOT_VERSION}" | |
| echo "Computed Maven version: ${MAVEN_VERSION}" | |
| publish-maven: | |
| name: Publish Maven | |
| needs: prepare_snapshot_version | |
| if: ${{ github.repository == 'apache/casbin-jcasbin' && github.event_name == 'push' && github.ref == 'refs/heads/master' }} | |
| uses: ./.github/workflows/maven-snapshot.yml | |
| with: | |
| maven_version: ${{ needs.prepare_snapshot_version.outputs.maven_version }} | |
| secrets: inherit | |
| semantic-release: | |
| name: Semantic Release | |
| needs: | |
| - prepare_snapshot_version | |
| - publish-maven | |
| if: ${{ github.repository == 'apache/casbin-jcasbin' && github.event_name == 'push' && github.ref == 'refs/heads/master' }} | |
| permissions: | |
| contents: write | |
| uses: ./.github/workflows/source-snapshot.yml | |
| with: | |
| version: ${{ needs.prepare_snapshot_version.outputs.version }} | |
| basename: ${{ needs.prepare_snapshot_version.outputs.basename }} | |
| previous_tag: ${{ needs.prepare_snapshot_version.outputs.previous_tag }} |