Merge pull request #308 from LedgerHQ/fix/sdk_update_ci

[ci][clean] Explicit source and destination branches when auto commit and push
This commit is contained in:
lpascal-ledger
2022-06-07 16:51:16 +02:00
committed by GitHub
2 changed files with 61 additions and 23 deletions

View File

@@ -21,10 +21,14 @@ inputs:
description: 'The directory in which the action will be performed' description: 'The directory in which the action will be performed'
required: true required: true
default: '.' default: '.'
branch: src_branch:
description: 'Checkout (or create) on a specific branch before commit/push' description: 'Checkout (or create) a specific branch before commit/push. Defaults to current branch'
required: true required: false
default: 'master' default: ''
dst_branch:
description: 'Push the created commit on a specific branch. Defaults to current branch'
required: false
default: ''
secret: secret:
description: 'A token allowing to push the commit on the repository' description: 'A token allowing to push the commit on the repository'
required: true required: true
@@ -43,38 +47,73 @@ runs:
git config --global user.name ${{ inputs.name }} git config --global user.name ${{ inputs.name }}
ORIGIN="$(pwd)" ORIGIN="$(pwd)"
cd ${{ inputs.directory }} cd ${{ inputs.directory }}
git switch ${{ inputs.branch }} 2>/dev/null || git switch -c ${{ inputs.branch }}
CURRENT_BRANCH=${GITHUB_REF#refs/heads/};
# calculating source branch
if [ -n "${{ inputs.src_branch }}" ]; \
then \
git switch ${{ inputs.src_branch }} 2>/dev/null || git switch -c ${{ inputs.src_branch }}; \
SRC_BRANCH=${{ inputs.src_branch }}; \
else \
SRC_BRANCH=`git branch --show-current`; \
if [ -z "$SRC_BRANCH" ]; \
then \
SRC_BRANCH=$CURRENT_BRANCH; \
fi \
fi
# calculating destination branch
if [ -n "${{ inputs.dst_branch }}" ]; \
then \
DST_BRANCH=${{ inputs.dst_branch }}; \
else \
DST_BRANCH=`git branch --show-current`; \
if [ -z "$DST_BRANCH" ]; \
then \
DST_BRANCH=$CURRENT_BRANCH; \
fi \
fi
echo "-----------------------------------------------------------" echo "-----------------------------------------------------------"
echo "Initial repo status" echo "Initial repo status"
git status git status
# checking changes, commit if needed
CHANGES="$(git status --porcelain ${{ inputs.files }})" CHANGES="$(git status --porcelain ${{ inputs.files }})"
if [ -z "${CHANGES}" ]; \ if [ -n "${CHANGES}" ]; \
then \ then \
echo -e "Changes:\n${CHANGES}"; \
git add ${{ inputs.files }}; \
echo "-----------------------------------------------------------"; \ echo "-----------------------------------------------------------"; \
echo "No changes, stopping now"; \ echo "Repo status before commit"; \
echo "COMMIT=NO" > $GITHUB_ENV; \ git status; \
cd "${ORIGIN}"; \ git commit -am "${{ inputs.message }}"; \
exit 0; \
fi fi
echo -e "Changes:\n${CHANGES}"
git add ${{ inputs.files }} # compute if a push is needed
echo "-----------------------------------------------------------" if [ -n "${CHANGES}" -o "$SRC_BRANCH" != "$DST_BRANCH" ]; \
echo "Repo status before commit" then \
git status PUSH="YES"; \
git commit -am "${{ inputs.message }}" else \
echo "COMMIT=YES" > $GITHUB_ENV PUSH="NO"; \
fi
git log -n 2 git log -n 2
cd "${ORIGIN}" cd "${ORIGIN}"
shell: bash
- run: echo "${{ env.COMMIT }}" echo " -- Env SRC_BRANCH: $SRC_BRANCH";
echo " -- Env DST_BRANCH: $DST_BRANCH";
echo " -- Env PUSH: $PUSH"
# exporting these variables for next steps
echo "##[set-output name=src_branch;]$(echo $SRC_BRANCH)";
echo "##[set-output name=dst_branch;]$(echo $DST_BRANCH)";
echo "##[set-output name=push;]$(echo $PUSH)";
shell: bash shell: bash
- name: Push commit - name: Push commit
if: ${{ env.COMMIT == 'YES' }} if: steps.commit.outputs.push == 'YES'
uses: ad-m/github-push-action@master uses: ad-m/github-push-action@master
with: with:
github_token: ${{ inputs.secret }} github_token: ${{ inputs.secret }}
branch: ${{ inputs.branch }} branch: ${{ steps.commit.outputs.src_branch }}:${{ steps.commit.outputs.dst_branch }}
directory: ${{ inputs.directory }} directory: ${{ inputs.directory }}
repository: ${{ inputs.repository }} repository: ${{ inputs.repository }}

View File

@@ -37,7 +37,7 @@ jobs:
with: with:
name: 'ldg-github-ci' name: 'ldg-github-ci'
directory: ethereum-plugin-sdk directory: ethereum-plugin-sdk
branch: ${{ steps.extract_branch.outputs.branch }} dst_branch: ${{ steps.extract_branch.outputs.branch }}
message: "[update] Branch ${{ steps.extract_branch.outputs.branch }} | Commit ${GITHUB_SHA}" message: "[update] Branch ${{ steps.extract_branch.outputs.branch }} | Commit ${GITHUB_SHA}"
secret: ${{ secrets.CI_BOT_TOKEN }} secret: ${{ secrets.CI_BOT_TOKEN }}
repository: LedgerHQ/ethereum-plugin-sdk repository: LedgerHQ/ethereum-plugin-sdk
@@ -47,7 +47,6 @@ jobs:
with: with:
name: 'ldg-github-ci' name: 'ldg-github-ci'
files: ethereum-plugin-sdk files: ethereum-plugin-sdk
branch: ${{ steps.extract_branch.outputs.branch }}
message: "[update][SDK] Branch ${{ steps.extract_branch.outputs.branch }} | Commit ${GITHUB_SHA}" message: "[update][SDK] Branch ${{ steps.extract_branch.outputs.branch }} | Commit ${GITHUB_SHA}"
secret: ${{ secrets.CI_BOT_TOKEN }} secret: ${{ secrets.CI_BOT_TOKEN }}
repository: LedgerHQ/app-ethereum repository: LedgerHQ/app-ethereum