Skip to content

Commit

Permalink
Merge pull request #405 from T0biii/add-bump-modules
Browse files Browse the repository at this point in the history
[CI] add Github action to bump modules commit Version
  • Loading branch information
GoliathLabs committed Apr 28, 2024
2 parents 4b3da3f + 91c4f2e commit 2f7b2db
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/bump-modules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
name: "Update Modules base"

on:
workflow_dispatch:

permissions:
contents: write # so it can comment
pull-requests: write # so it can create pull requests

jobs:
update-Modules:
runs-on: ubuntu-22.04
steps:
- name: Clone Firmware
uses: actions/checkout@v4

- name: Get update branch name
id: branch-name
run: echo "branch-name=update-modules-${{ github.event.inputs.branch }}-$(date +%s)" >> $GITHUB_OUTPUT

- name: Invoke update-modules
run: ./contrib/actions/update-modules.sh

- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
title: '[Update] ${{ github.event.inputs.branch }} modules'
body: |
Update modules for ${{ github.event.inputs.branch }} branche
- Auto-generated by [create-pull-request][1]
[1]: https://github.com/peter-evans/create-pull-request
commit-message: bump modules version
branch: ${{ steps.branch-name.outputs.branch-name }}

- name: Check outputs
if: ${{ steps.cpr.outputs.pull-request-number }}
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
2 changes: 2 additions & 0 deletions .github/workflows/firmware.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ on:
- '.github/ISSUE_TEMPLATE'
- '.github/*.yml'
- '.github/workflows/backport.yml'
- '.github/workflows/bump-modules.yml'
- 'contrib/sign.sh'
- 'contrib/actions/update-modules.sh'

jobs:
generate_target_matrix:
Expand Down
30 changes: 30 additions & 0 deletions contrib/actions/update-modules.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Die Datei, die die Repository-Informationen enthaelt
MODULES_FILE="modules"

# Durchlaufe die Datei, um alle Repository-URLs und ihre entsprechenden Commit-Variablen zu finden
# shellcheck disable=SC2094
while IFS= read -r line; do
# Überprüfe, ob die Zeile eine Repository-URL ist
if [[ "$line" == "PACKAGES_"*"_REPO="* ]]; then
# Extrahiere den Repository-Namen und die URL
REPO_NAME=$(echo "$line" | cut -d '=' -f 1)
REPO_URL=$(echo "$line" | cut -d '=' -f 2-)

# Den neuesten Commit für das Repository abrufen
NEW_COMMIT=$(git ls-remote "$REPO_URL" | grep -oE '[0-9a-f]{40}' | head -n1)

# Überprüfen, ob ein neuer Commit gefunden wurde
if [ -n "$NEW_COMMIT" ]; then
# Den Wert des Commits in der Datei aktualisieren
# shellcheck disable=SC2094
COMMIT_LINE=$(grep -n "${REPO_NAME/_REPO/_COMMIT}" "$MODULES_FILE" | cut -d ':' -f 1)
# shellcheck disable=SC2094
sed -i "${COMMIT_LINE}s/.*/${REPO_NAME/_REPO/_COMMIT}=$NEW_COMMIT/" "$MODULES_FILE"
echo "Der Wert von ${REPO_NAME/_REPO/_COMMIT} wurde auf den neuesten Commit ($NEW_COMMIT) aktualisiert."
else
echo "Fehler: Der neueste Commit f r $REPO_NAME konnte nicht abgerufen werden."
fi
fi
done < "$MODULES_FILE"

0 comments on commit 2f7b2db

Please sign in to comment.