|
| 1 | +name: Add information from latest push in a branch into main readme |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - '**' |
| 6 | +jobs: |
| 7 | + update-readme: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + steps: |
| 10 | + - name: Checkout main branch |
| 11 | + uses: actions/checkout@v4 |
| 12 | + with: |
| 13 | + ref: main |
| 14 | + token: ${{secrets.GITHUB_TOKEN}} |
| 15 | + - name: Get latest commit |
| 16 | + id: commit_info |
| 17 | + run: | |
| 18 | + git fetch origin "${{ github.ref_name }}" |
| 19 | + BRANCH="${{ github.ref_name }}" |
| 20 | + MESSAGE=$(git log origin/"${{ github.ref_name }}" -1 --pretty=%s) |
| 21 | + ID=$(git log origin/"${{ github.ref_name }}" -1 --pretty=%H) |
| 22 | + SHORT_ID=$(git log origin/"${{ github.ref_name }}" -1 --pretty=%h) |
| 23 | + URL="${{github.server_url}}/${{github.repository}}" |
| 24 | + echo "branch=$BRANCH" >> $GITHUB_OUTPUT |
| 25 | + echo "message=$MESSAGE" >> $GITHUB_OUTPUT |
| 26 | + echo "id=$ID" >> $GITHUB_OUTPUT |
| 27 | + echo "short_id=$SHORT_ID" >> $GITHUB_OUTPUT |
| 28 | + echo "url=$URL" >> $GITHUB_OUTPUT |
| 29 | + # Handle description with heredoc to support multiline and special characters |
| 30 | + { |
| 31 | + echo 'description<<EOF' |
| 32 | + git log origin/"${{ github.ref_name }}" -1 --pretty=%b # ← was hardcoded "front-end" |
| 33 | + echo EOF |
| 34 | + } >> $GITHUB_OUTPUT |
| 35 | + - name: Update README |
| 36 | + run: | |
| 37 | + cat > dev-info.md << 'EOF' |
| 38 | + ## Currently in Development |
| 39 | + **Branch:** ${{ steps.commit_info.outputs.branch }} |
| 40 | + **Commit:** ${{ steps.commit_info.outputs.message }} |
| 41 | + **Description:** ${{ steps.commit_info.outputs.description }} |
| 42 | + **Commit ID:** `${{ steps.commit_info.outputs.short_id }}` |
| 43 | + [View Branch](${{ steps.commit_info.outputs.url }}/tree/${{ steps.commit_info.outputs.branch }}) | [View Commit](${{ steps.commit_info.outputs.url }}/commit/${{ steps.commit_info.outputs.id }}) |
| 44 | + --- |
| 45 | + EOF |
| 46 | + if [ -f README.md ]; then |
| 47 | + sed -i '/## Currently in Development/,/^---$/d' README.md |
| 48 | + cat dev-info.md README.md > temp.md |
| 49 | + mv temp.md README.md |
| 50 | + else |
| 51 | + mv dev-info.md README.md |
| 52 | + fi |
| 53 | + rm -f dev-info.md |
| 54 | + - name: Commit and push changes |
| 55 | + run: | |
| 56 | + git config user.name "github-actions[bot]" |
| 57 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 58 | + git add README.md |
| 59 | + git diff --quiet && git diff --staged --quiet || (git commit -m "Update README with latest ${{ github.ref_name }} branch commit info" && git push) |
0 commit comments