|
| 1 | +name: Create versioned release |
| 2 | +# Test, build, and publish a release draft on new vX.Y.Z tag |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - "v*" |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + name: Create versioned release draft |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v1 |
| 16 | + |
| 17 | + - name: Generate version string |
| 18 | + id: get-version |
| 19 | + run: | |
| 20 | + VERSION=$(ant -q -S print_version) |
| 21 | + SHORT=$(echo "${VERSION}" | cut -d. -f-2) |
| 22 | + BUILD=$(cat .build.number | grep build.number | cut -f2 -d"=") |
| 23 | + echo "::set-output name=BUILD::$BUILD" |
| 24 | + echo "::set-output name=SHORT::$SHORT" |
| 25 | + echo "::set-output name=VERSION::$VERSION" |
| 26 | + echo "::set-output name=TAG::$(echo "v${VERSION}")" |
| 27 | +
|
| 28 | + REFTAG="$(echo "$GITHUB_REF" | awk -F/ '{print $NF}')" |
| 29 | + echo "::set-output name=REFTAG::$REFTAG" |
| 30 | +
|
| 31 | + - name: Sanity check |
| 32 | + id: sanity_check |
| 33 | + run: | |
| 34 | + # env |
| 35 | + BUILD=${{ steps.get-version.outputs.BUILD }} |
| 36 | + SHORT=${{ steps.get-version.outputs.SHORT }} |
| 37 | + VERSION=${{ steps.get-version.outputs.VERSION }} |
| 38 | + TAG=${{ steps.get-version.outputs.TAG }} |
| 39 | + REFTAG=${{ steps.get-version.outputs.REFTAG }} |
| 40 | + # tag is v1.2[.3]-567[.abc4] |
| 41 | + if [[ "$TAG" =~ ^v[0-9][0-9]*[.][0-9][0-9]*([.][0-9][0-9]*)?(-[1-9][0-9]*)([.][a-z][a-z0-9]*)?$ ]]; then |
| 42 | + echo tag $TAG okay |
| 43 | + else |
| 44 | + echo "tag (${VERSION},${BASE},${SHORT},${BUILD}) $TAG not okay!" |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | +
|
| 48 | + # version is 1.2[.3]-567[.abc4] |
| 49 | + if [[ "${VERSION}" =~ ^[0-9][0-9]*[.][0-9][0-9]*([.][0-9][0-9]*)?(-[1-9][0-9]*)([.][a-z][a-z0-9]*)?$ ]]; then |
| 50 | + echo version $VERSION okay |
| 51 | + else |
| 52 | + echo "version (${VERSION},${BASE},${SHORT},${BUILD}) $VERSION not okay!" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | +
|
| 56 | + # git tag has correct version |
| 57 | + if [[ "$TAG" == "$REFTAG" ]]; then |
| 58 | + echo tags match |
| 59 | + else |
| 60 | + echo "WARNING: $TAG <> $REFTAG" |
| 61 | + TAG=$REFTAG |
| 62 | + # exit 1 |
| 63 | + fi |
| 64 | + echo "::set-output name=TAG::$TAG" |
| 65 | +
|
| 66 | + # most recent tag has older build number |
| 67 | + LASTTAG=$(git tag -l v* --sort='-committerdate') |
| 68 | + OLDBUILD=$(git show ${LASTTAG}:.build.number | grep build.number | cut -f2 -d"=") |
| 69 | + if [[ $BUILD == $OLDBUILD ]]; then |
| 70 | + echo "build.number $BUILD has not changed since most recent tag ${LASTTAG}, please update by running ant build locally!" |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | +
|
| 74 | + - name: Test with ant |
| 75 | + run: | |
| 76 | + ant -noinput -buildfile build.xml run_tests |
| 77 | + fails=$(grep -L "Failures: 0, Errors: 0" test/junit/TEST-*) |
| 78 | + if [ -n "$fails" ]; then |
| 79 | + echo Errors in $fails |
| 80 | + cat $fails |
| 81 | + exit 1 |
| 82 | + fi |
| 83 | + # do not exit before all commands are executed |
| 84 | + shell: bash --noprofile --norc -o pipefail {0} |
| 85 | + |
| 86 | + - name: Build with ant |
| 87 | + run: | |
| 88 | + ant -noinput -buildfile build.xml distribute |
| 89 | +
|
| 90 | + - name: Read RELEASENOTES and CHANGELOG |
| 91 | + id: changelog |
| 92 | + run: | |
| 93 | + value=$(cat RELEASENOTES.txt | iconv -f ISO-8859-1; echo -e '\n## Excerpt from CHANGELOG.txt\n\n'; head -20 CHANGELOG.txt | iconv -f ISO-8859-1; echo -e '\n...\n') |
| 94 | + value="${value//'%'/'%25'}" |
| 95 | + value="${value//$'\n'/'%0A'}" |
| 96 | + value="${value//$'\r'/'%0D'}" |
| 97 | + echo "::set-output name=BODY::$value" |
| 98 | +
|
| 99 | + - name: prepare meta |
| 100 | + id: prepare-meta |
| 101 | + run: | |
| 102 | + set -x |
| 103 | + if [[ "${{ steps.sanity_check.outputs.TAG }}" =~ .*-([0-9]*[.])?([a-zA-Z][a-zA-Z]*).* ]]; then |
| 104 | + TYPE=$(echo ${{ steps.sanity_check.outputs.TAG }} | sed -e "s/.*-\([0-9]*[.]\)\?\([a-zA-Z][a-zA-Z]*\).*/\2/") |
| 105 | + else |
| 106 | + TYPE=stable |
| 107 | + fi |
| 108 | + if [[ ! "$TYPE" =~ ^[a-zA-Z]+$ ]]; then |
| 109 | + echo "invalid type $TYPE" |
| 110 | + exit 1 |
| 111 | + fi |
| 112 | + echo "::set-output name=TYPE::$TYPE" |
| 113 | +
|
| 114 | + - name: Release |
| 115 | + uses: softprops/action-gh-release@v1 |
| 116 | + with: |
| 117 | + target_commitish: master |
| 118 | + tag_name: ${{ steps.get-version.outputs.TAG }} |
| 119 | + draft: true |
| 120 | + prerelease: false |
| 121 | + fail_on_unmatched_files: false |
| 122 | + name: Release v${{ steps.get-version.outputs.VERSION }} (${{ steps.prepare-meta.outputs.TYPE }}) |
| 123 | + body: ${{ steps.changelog.outputs.BODY }} |
| 124 | + files: | |
| 125 | + README.md |
| 126 | + VERSION |
| 127 | + moooooo_release.v${{ steps.get-version.outputs.VERSION }} |
0 commit comments