Skip to content

Commit

Permalink
Changes for PowerAPI monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Test name committed Mar 15, 2024
1 parent 6ef79a1 commit d3b5042
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 122 deletions.
98 changes: 39 additions & 59 deletions .github/workflows/attach_debug_apk_to_release.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,44 @@
name: Attach Debug APK To Release

on:
release:
types:
- published

jobs:
attach-apks:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
runs-on: self-hosted
steps:
- name: Clone repository
uses: actions/checkout@v4
with:
ref: ${{ env.GITHUB_REF }}

- name: Build and attach APK to release
shell: bash {0}
run: |
exit_on_error() {
echo "$1"
echo "Deleting '$RELEASE_VERSION_NAME' release and '$GITHUB_REF' tag"
hub release delete "$RELEASE_VERSION_NAME"
git push --delete origin "$GITHUB_REF"
exit 1
}
echo "Setting vars"
RELEASE_VERSION_NAME="${GITHUB_REF/refs\/tags\//}"
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
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."
fi
APK_DIR_PATH="./app/build/outputs/apk/debug"
APK_VERSION_TAG="$RELEASE_VERSION_NAME+github-debug"
APK_BASENAME_PREFIX="termux-tasker_$APK_VERSION_TAG"
echo "Building APK for '$RELEASE_VERSION_NAME' release"
export TERMUX_TASKER_APK_VERSION_TAG="$APK_VERSION_TAG" # Used by app/build.gradle
if ! ./gradlew assembleDebug; then
exit_on_error "Build failed for '$RELEASE_VERSION_NAME' release."
fi
echo "Validating APK"
if ! test -f "$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk"; then
files_found="$(ls "$APK_DIR_PATH")"
exit_on_error "Failed to find built APK at '$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk'. Files found: "$'\n'"$files_found"
fi
echo "Generating sha25sums file"
if ! (cd "$APK_DIR_PATH"; sha256sum "${APK_BASENAME_PREFIX}.apk" > sha256sums); then
exit_on_error "Generate sha25sums failed for '$RELEASE_VERSION_NAME' release."
fi
echo "Attaching APK to github release"
if ! hub release edit \
-m "" \
-a "$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk" \
-a "$APK_DIR_PATH/sha256sums" \
"$RELEASE_VERSION_NAME"; then
exit_on_error "Attach APK to release failed for '$RELEASE_VERSION_NAME' release."
fi
- continue-on-error: true
name: Clone repository
uses: actions/checkout@v4
with:
ref: ${{ env.GITHUB_REF }}
- continue-on-error: true
name: Build and attach APK to release
run: "exit_on_error() {\n echo \"$1\"\n echo \"Deleting '$RELEASE_VERSION_NAME'\
\ release and '$GITHUB_REF' tag\"\n hub release delete \"$RELEASE_VERSION_NAME\"\
\n git push --delete origin \"$GITHUB_REF\"\n exit 1\n}\n\necho \"Setting\
\ vars\"\nRELEASE_VERSION_NAME=\"${GITHUB_REF/refs\\/tags\\//}\"\nif ! 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\n 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.\"\nfi\n\nAPK_DIR_PATH=\"./app/build/outputs/apk/debug\"\
\nAPK_VERSION_TAG=\"$RELEASE_VERSION_NAME+github-debug\"\nAPK_BASENAME_PREFIX=\"\
termux-tasker_$APK_VERSION_TAG\"\n\necho \"Building APK for '$RELEASE_VERSION_NAME'\
\ release\"\nexport TERMUX_TASKER_APK_VERSION_TAG=\"$APK_VERSION_TAG\" # Used\
\ by app/build.gradle\nif ! ./gradlew assembleDebug; then\n exit_on_error\
\ \"Build failed for '$RELEASE_VERSION_NAME' release.\"\nfi\n\necho \"Validating\
\ APK\"\nif ! test -f \"$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk\"; then\n\
\ files_found=\"$(ls \"$APK_DIR_PATH\")\"\n exit_on_error \"Failed to find\
\ built APK at '$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk'. Files found: \"\
$'\\n'\"$files_found\"\nfi\n\necho \"Generating sha25sums file\"\nif ! (cd\
\ \"$APK_DIR_PATH\"; sha256sum \"${APK_BASENAME_PREFIX}.apk\" > sha256sums);\
\ then\n exit_on_error \"Generate sha25sums failed for '$RELEASE_VERSION_NAME'\
\ release.\"\nfi\n\necho \"Attaching APK to github release\"\nif ! hub release\
\ edit \\\n-m \"\" \\\n-a \"$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk\" \\\n\
-a \"$APK_DIR_PATH/sha256sums\" \\\n\"$RELEASE_VERSION_NAME\"; then\n exit_on_error\
\ \"Attach APK to release failed for '$RELEASE_VERSION_NAME' release.\"\n\
fi\n"
shell: bash {0}
name: Attach Debug APK To Release
on:
repository_dispatch:
types: trigger-ga___attach_debug_apk_to_release.yml
115 changes: 52 additions & 63 deletions .github/workflows/debug_build.yml
Original file line number Diff line number Diff line change
@@ -1,66 +1,55 @@
name: Build

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
runs-on: self-hosted
steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Build APK
shell: bash {0}
run: |
exit_on_error() { echo "$1"; exit 1; }
echo "Setting vars"
# Set RELEASE_VERSION_NAME to "<CURRENT_VERSION_NAME>+<last_commit_hash>"
CURRENT_VERSION_NAME_REGEX='\s+versionName "([^"]+)"$'
CURRENT_VERSION_NAME="$(grep -m 1 -E "$CURRENT_VERSION_NAME_REGEX" ./app/build.gradle | sed -r "s/$CURRENT_VERSION_NAME_REGEX/\1/")"
RELEASE_VERSION_NAME="v$CURRENT_VERSION_NAME+${GITHUB_SHA:0:7}" # The "+" is necessary so that versioning precedence is not affected
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
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."
fi
APK_DIR_PATH="./app/build/outputs/apk/debug"
APK_VERSION_TAG="$RELEASE_VERSION_NAME-github-debug" # Note the "-", GITHUB_SHA will already have "+" before it
APK_BASENAME_PREFIX="termux-tasker_$APK_VERSION_TAG"
# Used by attachment steps later
echo "APK_DIR_PATH=$APK_DIR_PATH" >> $GITHUB_ENV
echo "APK_VERSION_TAG=$APK_VERSION_TAG" >> $GITHUB_ENV
echo "APK_BASENAME_PREFIX=$APK_BASENAME_PREFIX" >> $GITHUB_ENV
echo "Building APK for '$RELEASE_VERSION_NAME' build"
export TERMUX_TASKER_APP_VERSION_NAME="${RELEASE_VERSION_NAME/v/}" # Used by app/build.gradle
export TERMUX_TASKER_APK_VERSION_TAG="$APK_VERSION_TAG" # Used by app/build.gradle
if ! ./gradlew assembleDebug; then
exit_on_error "Build failed for '$RELEASE_VERSION_NAME' build."
fi
echo "Validating APK"
if ! test -f "$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk"; then
files_found="$(ls "$APK_DIR_PATH")"
exit_on_error "Failed to find built APK at '$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk'. Files found: "$'\n'"$files_found"
fi
echo "Generating sha25sums file"
if ! (cd "$APK_DIR_PATH"; sha256sum "${APK_BASENAME_PREFIX}.apk" > sha256sums); then
exit_on_error "Generate sha25sums failed for '$RELEASE_VERSION_NAME' release."
fi
- name: Attach files
uses: actions/upload-artifact@v4
with:
name: ${{ env.APK_BASENAME_PREFIX }}
path: |
${{ env.APK_DIR_PATH }}/${{ env.APK_BASENAME_PREFIX }}.apk
${{ env.APK_DIR_PATH }}/sha256sums
${{ env.APK_DIR_PATH }}/output-metadata.json
- continue-on-error: true
name: Clone repository
uses: actions/checkout@v4
- continue-on-error: true
name: Build APK
run: "exit_on_error() { echo \"$1\"; exit 1; }\n\necho \"Setting vars\"\n# Set\
\ RELEASE_VERSION_NAME to \"<CURRENT_VERSION_NAME>+<last_commit_hash>\"\n\
CURRENT_VERSION_NAME_REGEX='\\s+versionName \"([^\"]+)\"$'\nCURRENT_VERSION_NAME=\"\
$(grep -m 1 -E \"$CURRENT_VERSION_NAME_REGEX\" ./app/build.gradle | sed -r\
\ \"s/$CURRENT_VERSION_NAME_REGEX/\\1/\")\"\nRELEASE_VERSION_NAME=\"v$CURRENT_VERSION_NAME+${GITHUB_SHA:0:7}\"\
\ # The \"+\" is necessary so that versioning precedence is not affected\n\
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\n 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.\"\
\nfi\n\nAPK_DIR_PATH=\"./app/build/outputs/apk/debug\"\nAPK_VERSION_TAG=\"\
$RELEASE_VERSION_NAME-github-debug\" # Note the \"-\", GITHUB_SHA will already\
\ have \"+\" before it\nAPK_BASENAME_PREFIX=\"termux-tasker_$APK_VERSION_TAG\"\
\n\n# Used by attachment steps later\necho \"APK_DIR_PATH=$APK_DIR_PATH\"\
\ >> $GITHUB_ENV\necho \"APK_VERSION_TAG=$APK_VERSION_TAG\" >> $GITHUB_ENV\n\
echo \"APK_BASENAME_PREFIX=$APK_BASENAME_PREFIX\" >> $GITHUB_ENV\n\necho \"\
Building APK for '$RELEASE_VERSION_NAME' build\"\nexport TERMUX_TASKER_APP_VERSION_NAME=\"\
${RELEASE_VERSION_NAME/v/}\" # Used by app/build.gradle\nexport TERMUX_TASKER_APK_VERSION_TAG=\"\
$APK_VERSION_TAG\" # Used by app/build.gradle\nif ! ./gradlew assembleDebug;\
\ then\n exit_on_error \"Build failed for '$RELEASE_VERSION_NAME' build.\"\
\nfi\n\necho \"Validating APK\"\nif ! test -f \"$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk\"\
; then\n files_found=\"$(ls \"$APK_DIR_PATH\")\"\n exit_on_error \"Failed\
\ to find built APK at '$APK_DIR_PATH/${APK_BASENAME_PREFIX}.apk'. Files found:\
\ \"$'\\n'\"$files_found\"\nfi\n\necho \"Generating sha25sums file\"\nif !\
\ (cd \"$APK_DIR_PATH\"; sha256sum \"${APK_BASENAME_PREFIX}.apk\" > sha256sums);\
\ then\n exit_on_error \"Generate sha25sums failed for '$RELEASE_VERSION_NAME'\
\ release.\"\nfi\n"
shell: bash {0}
- continue-on-error: true
name: Attach files
uses: actions/upload-artifact@v4
with:
name: ${{ env.APK_BASENAME_PREFIX }}
path: '${{ env.APK_DIR_PATH }}/${{ env.APK_BASENAME_PREFIX }}.apk
${{ env.APK_DIR_PATH }}/sha256sums
${{ env.APK_DIR_PATH }}/output-metadata.json
'
name: Build
on:
repository_dispatch:
types: trigger-ga___debug_build.yml

0 comments on commit d3b5042

Please sign in to comment.