|
| 1 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The ASF licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | + |
| 18 | +name: Build Source Snapshot |
| 19 | + |
| 20 | +on: |
| 21 | + push: |
| 22 | + branches: |
| 23 | + - master |
| 24 | + workflow_dispatch: |
| 25 | + |
| 26 | +permissions: |
| 27 | + contents: write |
| 28 | + |
| 29 | +jobs: |
| 30 | + build-source-snapshot: |
| 31 | + if: ${{ github.repository == 'apache/casbin' }} |
| 32 | + runs-on: ubuntu-latest |
| 33 | + steps: |
| 34 | + - name: Checkout |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + fetch-depth: 0 |
| 38 | + |
| 39 | + - name: Compute snapshot metadata |
| 40 | + id: snapshot |
| 41 | + run: | |
| 42 | + LATEST_RELEASE_TAG="$( |
| 43 | + git tag --list 'v*' | |
| 44 | + grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | |
| 45 | + sort -V | |
| 46 | + tail -n 1 |
| 47 | + )" |
| 48 | +
|
| 49 | + if [ -z "${LATEST_RELEASE_TAG}" ]; then |
| 50 | + BASE_VERSION="0.1.0" |
| 51 | + else |
| 52 | + RELEASE_VERSION="${LATEST_RELEASE_TAG#v}" |
| 53 | + IFS='.' read -r MAJOR MINOR PATCH <<< "${RELEASE_VERSION}" |
| 54 | + BASE_VERSION="${MAJOR}.$((MINOR + 1)).0" |
| 55 | + fi |
| 56 | +
|
| 57 | + ESCAPED_BASE_VERSION="${BASE_VERSION//./\\.}" |
| 58 | + LAST_SNAPSHOT_NUMBER="$( |
| 59 | + git tag --list "v${BASE_VERSION}-snapshot.*" | |
| 60 | + sed -nE "s/^v${ESCAPED_BASE_VERSION}-snapshot\\.([0-9]+)$/\\1/p" | |
| 61 | + sort -n | |
| 62 | + tail -n 1 |
| 63 | + )" |
| 64 | + LAST_SNAPSHOT_NUMBER="${LAST_SNAPSHOT_NUMBER:-0}" |
| 65 | + NEXT_SNAPSHOT_NUMBER="$((LAST_SNAPSHOT_NUMBER + 1))" |
| 66 | + SNAPSHOT_VERSION="v${BASE_VERSION}-snapshot.${NEXT_SNAPSHOT_NUMBER}" |
| 67 | + BASENAME="casbin-${SNAPSHOT_VERSION#v}-src" |
| 68 | +
|
| 69 | + if [ "${LAST_SNAPSHOT_NUMBER}" -gt 0 ]; then |
| 70 | + CHANGELOG_START_TAG="v${BASE_VERSION}-snapshot.${LAST_SNAPSHOT_NUMBER}" |
| 71 | + else |
| 72 | + CHANGELOG_START_TAG="${LATEST_RELEASE_TAG}" |
| 73 | + fi |
| 74 | +
|
| 75 | + echo "latest_release_tag=${LATEST_RELEASE_TAG}" >> "${GITHUB_OUTPUT}" |
| 76 | + echo "changelog_start_tag=${CHANGELOG_START_TAG}" >> "${GITHUB_OUTPUT}" |
| 77 | + echo "base_version=${BASE_VERSION}" >> "${GITHUB_OUTPUT}" |
| 78 | + echo "number=${NEXT_SNAPSHOT_NUMBER}" >> "${GITHUB_OUTPUT}" |
| 79 | + echo "version=${SNAPSHOT_VERSION}" >> "${GITHUB_OUTPUT}" |
| 80 | + echo "basename=${BASENAME}" >> "${GITHUB_OUTPUT}" |
| 81 | +
|
| 82 | + - name: Generate snapshot release notes |
| 83 | + run: | |
| 84 | + PREVIOUS_TAG="${{ steps.snapshot.outputs.changelog_start_tag }}" |
| 85 | + CURRENT_TAG="${{ steps.snapshot.outputs.version }}" |
| 86 | + CURRENT_VERSION="${CURRENT_TAG#v}" |
| 87 | + RELEASE_DATE="$(date -u +%F)" |
| 88 | + RANGE="HEAD" |
| 89 | +
|
| 90 | + if [ -n "${PREVIOUS_TAG}" ]; then |
| 91 | + RANGE="${PREVIOUS_TAG}..HEAD" |
| 92 | + fi |
| 93 | +
|
| 94 | + FEATURES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(feat)(\(.+\))?: ' || true)" |
| 95 | + FIXES="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(fix)(\(.+\))?: ' || true)" |
| 96 | + DOCS="$(git log --pretty=format:'%s (%h)' "${RANGE}" | grep -Ei '^(docs?|doc)(\(.+\))?: ' || true)" |
| 97 | +
|
| 98 | + { |
| 99 | + if [ -n "${PREVIOUS_TAG}" ]; then |
| 100 | + echo "# [${CURRENT_VERSION}](https://github.com/${GITHUB_REPOSITORY}/compare/${PREVIOUS_TAG}...${CURRENT_TAG}) (${RELEASE_DATE})" |
| 101 | + else |
| 102 | + echo "# ${CURRENT_VERSION} (${RELEASE_DATE})" |
| 103 | + fi |
| 104 | + echo |
| 105 | + if [ -n "${FEATURES}" ]; then |
| 106 | + echo "## Features" |
| 107 | + echo |
| 108 | + printf '%s\n' "${FEATURES}" | sed 's/^/- /' |
| 109 | + echo |
| 110 | + fi |
| 111 | +
|
| 112 | + if [ -n "${FIXES}" ]; then |
| 113 | + echo "## Fixes" |
| 114 | + echo |
| 115 | + printf '%s\n' "${FIXES}" | sed 's/^/- /' |
| 116 | + echo |
| 117 | + fi |
| 118 | +
|
| 119 | + if [ -n "${DOCS}" ]; then |
| 120 | + echo "## Docs" |
| 121 | + echo |
| 122 | + printf '%s\n' "${DOCS}" | sed 's/^/- /' |
| 123 | + echo |
| 124 | + fi |
| 125 | +
|
| 126 | + if [ -z "${FEATURES}${FIXES}${DOCS}" ]; then |
| 127 | + echo "## Notes" |
| 128 | + echo |
| 129 | + echo "- No feat/fix/doc commits were found in this snapshot range." |
| 130 | + fi |
| 131 | + } > SNAPSHOT_RELEASE_NOTES.md |
| 132 | +
|
| 133 | + - name: Create source archives |
| 134 | + run: | |
| 135 | + mkdir -p dist |
| 136 | + git archive --format=tar.gz --prefix="${{ steps.snapshot.outputs.basename }}/" -o "dist/${{ steps.snapshot.outputs.basename }}.tar.gz" HEAD |
| 137 | + git archive --format=zip --prefix="${{ steps.snapshot.outputs.basename }}/" -o "dist/${{ steps.snapshot.outputs.basename }}.zip" HEAD |
| 138 | +
|
| 139 | + - name: Create snapshot GitHub release |
| 140 | + uses: softprops/action-gh-release@v2 |
| 141 | + with: |
| 142 | + tag_name: ${{ steps.snapshot.outputs.version }} |
| 143 | + target_commitish: ${{ github.sha }} |
| 144 | + name: ${{ steps.snapshot.outputs.version }} |
| 145 | + body_path: SNAPSHOT_RELEASE_NOTES.md |
| 146 | + draft: false |
| 147 | + prerelease: false |
| 148 | + files: | |
| 149 | + dist/${{ steps.snapshot.outputs.basename }}.tar.gz |
| 150 | + dist/${{ steps.snapshot.outputs.basename }}.zip |
0 commit comments