|
1 | 1 | name: Build |
2 | 2 |
|
3 | | -on: push |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - master |
4 | 10 |
|
5 | 11 | jobs: |
6 | 12 | build: |
7 | 13 | runs-on: ubuntu-latest |
8 | 14 | steps: |
9 | | - - name: Clone repository |
10 | | - uses: actions/checkout@v2 |
11 | | - - name: Build |
12 | | - run: | |
13 | | - ./gradlew assembleDebug |
14 | | - - name: Store generated APK file |
15 | | - uses: actions/upload-artifact@v2 |
16 | | - with: |
17 | | - name: termux-tasker |
18 | | - path: | |
19 | | - ./app/build/outputs/apk/debug/termux-tasker-debug.apk |
20 | | - ./app/build/outputs/apk/debug/output-metadata.json |
| 15 | + - name: Clone repository |
| 16 | + uses: actions/checkout@v2 |
| 17 | + |
| 18 | + - name: Build APK |
| 19 | + shell: bash {0} |
| 20 | + run: | |
| 21 | + exit_on_error() { echo "$1"; exit 1; } |
| 22 | +
|
| 23 | + echo "Setting vars" |
| 24 | + # Set RELEASE_VERSION_NAME to "<CURRENT_VERSION_NAME>+<last_commit_hash>" |
| 25 | + CURRENT_VERSION_NAME_REGEX='\s+versionName "([^"]+)"$' |
| 26 | + CURRENT_VERSION_NAME="$(grep -m 1 -E "$CURRENT_VERSION_NAME_REGEX" ./app/build.gradle | sed -r "s/$CURRENT_VERSION_NAME_REGEX/\1/")" |
| 27 | + RELEASE_VERSION_NAME="v$CURRENT_VERSION_NAME+${GITHUB_SHA:0:7}" # The "+" is necessary so that versioning precedence is not affected |
| 28 | + if ! printf "%s" "${RELEASE_VERSION_NAME/v/}" | grep -qP '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'; then |
| 29 | + exit_on_error "The versionName '${RELEASE_VERSION_NAME/v/}' is not a valid version as per semantic version '2.0.0' spec in the format 'major.minor.patch(-prerelease)(+buildmetadata)'. https://semver.org/spec/v2.0.0.html." |
| 30 | + fi |
| 31 | +
|
| 32 | + APK_DIR_PATH="./app/build/outputs/apk/debug" |
| 33 | + APK_VERSION_TAG="$RELEASE_VERSION_NAME-github-debug" # Note the "-", GITHUB_SHA will already have "+" before it |
| 34 | + APK_BASENAME_PREFIX="termux-tasker_$APK_VERSION_TAG" |
| 35 | +
|
| 36 | + # Used by attachment steps later |
| 37 | + echo "APK_DIR_PATH=$APK_DIR_PATH" >> $GITHUB_ENV |
| 38 | + echo "APK_VERSION_TAG=$APK_VERSION_TAG" >> $GITHUB_ENV |
| 39 | + echo "APK_BASENAME_PREFIX=$APK_BASENAME_PREFIX" >> $GITHUB_ENV |
| 40 | +
|
| 41 | + echo "Building APK for '$RELEASE_VERSION_NAME' build" |
| 42 | + export TERMUX_TASKER_APP_VERSION_NAME="${RELEASE_VERSION_NAME/v/}" # Used by app/build.gradle |
| 43 | + export TERMUX_TASKER_APK_VERSION_TAG="$APK_VERSION_TAG" # Used by app/build.gradle |
| 44 | + if ! ./gradlew assembleDebug; then |
| 45 | + exit_on_error "Build failed for '$RELEASE_VERSION_NAME' build." |
| 46 | + fi |
| 47 | +
|
| 48 | + echo "Validating APK" |
| 49 | + if ! test -f "$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk"; then |
| 50 | + files_found="$(ls "$APK_DIR_PATH")" |
| 51 | + exit_on_error "Failed to find built APK at '$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk'. Files found: "$'\n'"$files_found" |
| 52 | + fi |
| 53 | +
|
| 54 | + echo "Generating sha25sums file" |
| 55 | + if ! (cd "$APK_DIR_PATH"; sha256sum "${APK_BASENAME_PREFIX}.apk" > sha256sums); then |
| 56 | + exit_on_error "Generate sha25sums failed for '$RELEASE_VERSION_NAME' release." |
| 57 | + fi |
| 58 | +
|
| 59 | + - name: Attach files |
| 60 | + uses: actions/upload-artifact@v2 |
| 61 | + with: |
| 62 | + name: ${{ env.APK_BASENAME_PREFIX }} |
| 63 | + path: | |
| 64 | + ${{ env.APK_DIR_PATH }}/${{ env.APK_BASENAME_PREFIX }}.apk |
| 65 | + ${{ env.APK_DIR_PATH }}/sha256sums |
| 66 | + ${{ env.APK_DIR_PATH }}/output-metadata.json |
0 commit comments