diff --git a/.github/workflows/gradle-wrapper-update.yml b/.github/workflows/gradle-wrapper-update.yml new file mode 100644 index 00000000..d6385cf8 --- /dev/null +++ b/.github/workflows/gradle-wrapper-update.yml @@ -0,0 +1,117 @@ +name: MT Update Gradle Wrapper +on: + workflow_dispatch: # manual + inputs: + gradle-version: + description: 'Gradle version to update to (e.g., 8.13)' + required: true + type: string + gradle-distribution-sha256-sum: + description: 'SHA256 checksum of the Gradle distribution (find at https://gradle.org/release-checksums/)' + required: true + type: string +# gh workflow run gradle-wrapper-update.yml --ref -f gradle-version=8.13 -f gradle-distribution-sha256-sum= +# gh run list --workflow=gradle-wrapper-update.yml +env: + MT_BOT_USER_NAME: ${{ vars.MT_BOT_USER_NAME }} + MT_BOT_USER_EMAIL: ${{ vars.MT_BOT_USER_EMAIL }} + MT_BRANCH_NAME: ${{ github.head_ref || github.ref_name }} +jobs: + MT-UPDATE-GRADLE-WRAPPER-JOB: + name: "MT Update Gradle wrapper" + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - name: MT select main repo checkout branch + id: mt-pick-main-repo-checkout-branch + env: + GH_TOKEN: ${{ github.token }} + run: | + MAIN_REPO_URL="https://github.com/mtransitapps/mtransit-for-android.git" + BRANCH_EXISTS=$(git ls-remote --heads $MAIN_REPO_URL $MT_BRANCH_NAME | wc -l); + if [ $BRANCH_EXISTS -eq 1 ]; then + CHECKOUT_BRANCH=$MT_BRANCH_NAME + else + echo "WARNING: no match for current branch!!!" + DEFAULT_REPO_BRANCH=$(gh api repos/mtransitapps/mtransit-for-android --jq '.default_branch'); + CHECKOUT_BRANCH=$DEFAULT_REPO_BRANCH + fi + echo "Checkout branch: '$CHECKOUT_BRANCH'." + echo "mt_checkout_branch=$CHECKOUT_BRANCH" >> "$GITHUB_OUTPUT" + - name: MT check out main repo + uses: actions/checkout@v6 + with: + repository: mtransitapps/mtransit-for-android + ref: ${{ steps.mt-pick-main-repo-checkout-branch.outputs.mt_checkout_branch }} + submodules: true + token: ${{ secrets.MT_PAT || secrets.GITHUB_TOKEN }} + fetch-depth: 0 + - name: MT check out submodules + run: ./checkout_submodules.sh + - name: MT check out this module repo branch + run: | + REPOSITORY_OWNER_AND_NAME=${{ github.repository }}; + REPOSITORY_NAME=$(basename $REPOSITORY_OWNER_AND_NAME); + echo "Repository name: '$REPOSITORY_NAME'." + echo "Fetching from repo '$REPOSITORY_NAME':" + git -C $REPOSITORY_NAME fetch -v --all; + echo "Checking out this repo '$REPOSITORY_NAME' workflow branch '$MT_BRANCH_NAME':" + git -C $REPOSITORY_NAME switch $MT_BRANCH_NAME; + echo "Pulling from repo '$REPOSITORY_NAME':" + git -C $REPOSITORY_NAME pull -v; + - name: MT setup + run: ./.github/actions/setup/run.sh + - name: MT set up JDK 17 + uses: actions/setup-java@v5 + with: + distribution: 'temurin' + java-version: '17' + - name: MT update gradle wrapper + run: | + echo "Updating Gradle wrapper to version ${{ inputs.gradle-version }}..." + ./gradlew wrapper --gradle-version ${{ inputs.gradle-version }} --gradle-distribution-sha256-sum=${{ inputs.gradle-distribution-sha256-sum }} + echo "Gradle wrapper updated successfully." + - name: MT copy gradle files to commons/shared + run: | + echo "Copying gradle files to commons/shared/..." + cp -R ./gradle commons/shared/ + cp ./gradlew commons/shared/ + cp ./gradlew.bat commons/shared/ + echo "Files copied successfully." + echo "Verifying copied files:" + ls -la commons/shared/gradle commons/shared/gradlew* + - name: MT commit and push changes + run: | + cd commons || exit 1; + git config user.name "$MT_BOT_USER_NAME"; + git config user.email "$MT_BOT_USER_EMAIL"; + git add -v shared/gradle*; + git diff --staged --quiet || git commit -m "Update Gradle wrapper to ${{ inputs.gradle-version }}"; + git push; + cd .. || exit 1; + - name: MT create pull request + env: + GH_TOKEN: ${{ secrets.MT_PAT || secrets.GITHUB_TOKEN }} + run: | + cd commons || exit 1; + PR_TITLE="Update Gradle wrapper to ${{ inputs.gradle-version }}" + PR_BODY="This PR updates the Gradle wrapper to version ${{ inputs.gradle-version }}. + + **Gradle Version:** ${{ inputs.gradle-version }} + **SHA256 Checksum:** ${{ inputs.gradle-distribution-sha256-sum }} + + Generated by workflow: ${{ github.workflow }} + Triggered by: @${{ github.actor }}" + # Check if PR already exists + EXISTING_PR=$(gh pr list --head "$MT_BRANCH_NAME" --json number --jq '.[0].number' || echo "") + + if [ -n "$EXISTING_PR" ]; then + echo "Pull request #$EXISTING_PR already exists for branch $MT_BRANCH_NAME" + gh pr view $EXISTING_PR + else + echo "Creating pull request..." + gh pr create --title "$PR_TITLE" --body "$PR_BODY" --head "$MT_BRANCH_NAME" || echo "PR creation failed or PR already exists" + fi + cd .. || exit 1; diff --git a/.gitignore b/.gitignore index 4b3d9e28..d2b18a2c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ # IntelliJ *.iml +# Gradle +.gradle/ + # TOML Dependency updater file *.updates.toml \ No newline at end of file