Support Albe protocol #1365
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: VersionReplace | |
on: | |
pull_request: | |
paths: | |
- 'FHEM/**' | |
- '.github/workflows/version.yml' | |
jobs: | |
pre_ci: | |
name: Prepare CI environment | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Project | |
uses: actions/checkout@v4 | |
with: | |
# We need to fetch with a depth of 2 for pull_request so we can do HEAD^2 | |
fetch-depth: 2 | |
# If this workflow was triggered by a push then resolve the commit message from HEAD | |
# It is stored in output steps, to be referenced with ${{ steps.push_get_commit_message.outputs.push_commit_message }} | |
- name: "[Push] Get commit message" | |
if: github.event_name == 'push' | |
id: push_get_commit_message | |
run: | | |
{ | |
echo 'pr_commit_message<<EOF' | |
git log --format=%B -n 1 HEAD | |
echo EOF | |
} >> $GITHUB_OUTPUT | |
# If this workflow was triggered by a pull request (open or synchronize!) then resolve the commit message from HEAD^2 | |
# It is stored in output steps, to be referenced with ${{ steps.pr_get_commit_message.outputs.pr_commit_message }} | |
- name: "[Pull Request] Get commit message" | |
if: github.event_name == 'pull_request' | |
id: pr_get_commit_message | |
run: | | |
{ | |
echo 'pr_commit_message<<EOF' | |
git log --format=%B -n 1 HEAD^2 | |
echo EOF | |
} >> $GITHUB_OUTPUT | |
# Finally we want to make the commit message available to other jobs. This can be done with job-level outputs | |
# However as we do not know whether the commit message was set in Push or Pull Request event we need to do some | |
# bash magic to resolve the one or the other | |
# | |
# For **Pull Request** events this will resolve to something like "$( [ -z "commit message pr" ] && echo "" || echo "commit message pr" )" which then resolves to just "commit message pr" | |
# | |
# For **Push** events this will resolve to something like "$( [ -z "" ] && echo "commit message push" || echo "" )" which then resolves to just "commit message push" | |
outputs: | |
commit_message: $( [ -z "${{ steps.pr_get_commit_message.outputs.pr_commit_message }}" ] && echo "${{ steps.push_get_commit_message.outputs.push_commit_message }}" || echo "${{ steps.pr_get_commit_message.outputs.pr_commit_message }}" ) | |
metadata: | |
# Do not run this job again if the last commit was a Update Versondate which comes from this workflow! | |
if: "!contains(needs.pre_ci.outputs.commit_message, 'Update Versiondate')" | |
needs: pre_ci | |
outputs: | |
matrix: ${{ steps.set-matrix.outputs.matrix }} | |
date: ${{ steps.date.outputs.date }} | |
datetime: ${{ steps.date.outputs.datetimestr }} | |
runs-on: ubuntu-latest | |
steps: | |
- id: file_changes | |
uses: tj-actions/changed-files@v44 | |
with: | |
json: true | |
quotepath: false | |
files: | | |
FHEM/**.pm | |
FHEM/lib/**.pm | |
lib/FHEM/**.pm | |
- name: Get current date | |
id: date | |
run: | | |
echo "date=$(date -u +'%Y%m%d')" >> $GITHUB_OUTPUT | |
echo "datetimestr=$(date -u +'%Y-%m-%d %T')" >> $GITHUB_OUTPUT | |
- name: Set matrix for build | |
id: set-matrix | |
if: ${{ github.event.sender != 'actions-user' }} | |
run: | |
echo "matrix={\"files\":${{ steps.file_changes.outputs.all_changed_files }}}" >> "$GITHUB_OUTPUT" | |
modify: | |
if: ${{ fromJSON( needs.metadata.outputs.matrix ).files[0] }} | |
continue-on-error: true | |
runs-on: ubuntu-latest | |
needs: metadata | |
strategy: | |
matrix: ${{ fromJson(needs.metadata.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Find Version String | |
if: endsWith(matrix.files, '00_SIGNALduino.pm') | |
id: versionList | |
uses: nguyenvanuyn96/str-find-action@master | |
with: | |
find: '\d\.\d\.\d' | |
include: "${{ matrix.files }}" | |
- uses: jungwinter/split@v2 | |
name: Split array result | |
if: ${{ steps.versionList.outputs.fileFoundCount > 0 }} | |
id: versions | |
with: | |
msg: '${{ steps.versionList.outputs.resultArray }}' | |
separator: ' ' | |
- name: Update SDUINO_VERSION date | |
if: endsWith(matrix.file, '00_SIGNALduino.pm') | |
uses: jacobtomlinson/gha-find-replace@v3.0.4 | |
with: | |
find: \w+\s+=>\s\'\d.\d.\d\+\d+\' | |
replace: "SDUINO_VERSION => '${{ steps.versions.outputs._1 }}+${{ needs.metadata.outputs.date }}'" | |
include: "${{ matrix.files }}" | |
- name: Update Date in ID line | |
uses: jacobtomlinson/gha-find-replace@v3.0.4 | |
with: | |
find: \d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\dZ\s[\w|-]+\s | |
replace: "${{ needs.metadata.outputs.datetime }}Z ${{ github.event.pull_request.user.login }} " | |
include: "${{ matrix.files }}" | |
- name: Artifactname | |
env: | |
ARTIFACT_NAME: "${{ matrix.files }}" | |
run: | | |
ARTIFACT_NAME=${{ env.ARTIFACT_NAME }} | |
ARTIFACT_NAME=$(basename $ARTIFACT_NAME) # get only the filename and use this as artifact name | |
echo ARTIFACT_NAME=${ARTIFACT_NAME} >> $GITHUB_ENV # update GitHub ENV vars | |
- name: Save updated Files in artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ env.ARTIFACT_NAME }} | |
retention-days: 1 | |
path: | | |
${{ matrix.files }} | |
commit: | |
permissions: | |
contents: write | |
runs-on: ubuntu-latest | |
needs: modify | |
name: Commit and Push back | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
fetch-depth: 0 | |
persist-credentials: false | |
- name: Download all modified artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: ${{ github.workspace }}/artifacts | |
- name: replace files from artifacts | |
run: | | |
for FPATH in ./artifacts/*/*.pm; do | |
FILE=$(basename $FPATH) | |
find ./FHEM -name "$FILE" -exec cp $FPATH "{}" \; | |
done | |
- name: update controls file (FHEM) | |
uses: fhem/fhem-controls-actions@v2.3.0 | |
with: | |
filename: controls_signalduino.txt | |
- name: update controls file (lib) | |
uses: fhem/fhem-controls-actions@v2.3.0 | |
with: | |
filename: controls_signalduino.txt | |
directory: FHEM/lib | |
writemode: a | |
- name: git commit back | |
id: commit | |
run: | | |
git config --global user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
git commit -m "Update Versiondate" -a && echo "status=true" >> $GITHUB_OUTPUT || true | |
- name: Wait for tests to succeed | |
if: ${{ steps.commit.outputs.status }} | |
uses: lewagon/wait-on-check-action@v1.3.4 | |
with: | |
running-workflow-name: 'Commit and Push back' | |
ref: ${{ github.head_ref }} | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
wait-interval: 20 | |
allowed-conclusions: success,skipped,cancelled,neutral | |
ignore-checks: codecov/patch | |
- name: git push | |
if: ${{ steps.commit.outputs.status }} | |
uses: ad-m/github-push-action@v0.8.0 | |
with: | |
github_token: ${{ secrets.GH_TOKEN }} | |
branch: ${{ github.head_ref }} | |
#- name: Push to branch | |
# uses: CasperWA/push-protected@v2 | |
# with: | |
# token: ${{ secrets.GH_TOKEN }} | |
# branch: ${{ github.head_ref }} | |
# #unprotect_reviews: true | |