|
| 1 | +name: Push Build Version Changes |
| 2 | + |
| 3 | +description: "Commits and pushes build version changes for mobile platforms" |
| 4 | + |
| 5 | +inputs: |
| 6 | + commit_message: |
| 7 | + description: "Commit message" |
| 8 | + required: true |
| 9 | + commit_paths: |
| 10 | + description: "Space-separated list of paths to check for changes (e.g. 'ios/file.txt android/another/file.xml')" |
| 11 | + required: true |
| 12 | + |
| 13 | +runs: |
| 14 | + using: "composite" |
| 15 | + steps: |
| 16 | + - name: Configure Git |
| 17 | + shell: bash |
| 18 | + run: | |
| 19 | + set -e |
| 20 | + git config --global user.email "action@github.com" |
| 21 | + git config --global user.name "Self GitHub Actions" |
| 22 | +
|
| 23 | + - name: Commit Changes |
| 24 | + shell: bash |
| 25 | + run: | |
| 26 | + set -e |
| 27 | + set -x |
| 28 | +
|
| 29 | + # Restore the logic for checking specific paths existence |
| 30 | + commit_paths_input="${{ inputs.commit_paths }}" |
| 31 | + paths_to_commit="" |
| 32 | +
|
| 33 | + for path in $commit_paths_input; do |
| 34 | + if [ ! -e "$path" ]; then |
| 35 | + echo "Error: Path $path does not exist" |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | + paths_to_commit="$paths_to_commit $path" |
| 39 | + done |
| 40 | +
|
| 41 | + if [ -z "$paths_to_commit" ]; then |
| 42 | + echo "No valid paths provided." |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | +
|
| 46 | + # Remove leading space if present |
| 47 | + paths_to_commit=$(echo "$paths_to_commit" | sed 's/^ *//') |
| 48 | +
|
| 49 | + # Stage ONLY the specified paths |
| 50 | + git add $paths_to_commit |
| 51 | +
|
| 52 | + # Check if there are staged changes ONLY in the specified paths |
| 53 | + if git diff --staged --quiet -- $paths_to_commit; then |
| 54 | + echo "No changes to commit in the specified paths: $paths_to_commit" |
| 55 | + else |
| 56 | + echo "Changes to be committed in paths: $paths_to_commit" |
| 57 | + # Show the staged diff for the specified paths |
| 58 | + git diff --cached -- $paths_to_commit |
| 59 | + git commit -m "chore: ${{ inputs.commit_message }} [github action]" |
| 60 | + fi |
| 61 | +
|
| 62 | + - name: Push Changes |
| 63 | + shell: bash |
| 64 | + run: | |
| 65 | + set -e |
| 66 | + set -x |
| 67 | +
|
| 68 | + if git rev-parse --verify HEAD >/dev/null 2>&1; then |
| 69 | + if [[ ${{ github.ref }} == refs/pull/* ]]; then |
| 70 | + CURRENT_BRANCH=${{ github.head_ref }} |
| 71 | + else |
| 72 | + CURRENT_BRANCH=$(echo ${{ github.ref }} | sed 's|refs/heads/||') |
| 73 | + fi |
| 74 | +
|
| 75 | + echo "Pushing changes to branch: $CURRENT_BRANCH" |
| 76 | + # Add --autostash to handle potential unstaged changes gracefully |
| 77 | + git pull --rebase --autostash origin $CURRENT_BRANCH || { |
| 78 | + echo "Failed to pull from $CURRENT_BRANCH" |
| 79 | + exit 1 |
| 80 | + } |
| 81 | + git push origin HEAD:$CURRENT_BRANCH || { |
| 82 | + echo "Failed to push to $CURRENT_BRANCH" |
| 83 | + exit 1 |
| 84 | + } |
| 85 | + else |
| 86 | + echo "No new commits to push" |
| 87 | + fi |
0 commit comments