From 17d4603da56b49e4b72c6531ba6d2db6dbcc3a31 Mon Sep 17 00:00:00 2001 From: andy Augustin Date: Thu, 29 Feb 2024 09:53:41 +0100 Subject: [PATCH] feat(#468): :sparkles: enable usage of github env variables within hooks (#469) * feat: :sparkles: hooks support env variables * feat: :sparkles: * doc: :memo: add information about using env variables * feat: :sparkles: cleanup --- .github/workflows/test_hooks.yml | 2 ++ README.md | 19 ++++++++++++++++++- src/sync_common.sh | 2 +- templatesync.yml | 1 + 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test_hooks.yml b/.github/workflows/test_hooks.yml index 478fd715..6fe9ffbb 100644 --- a/.github/workflows/test_hooks.yml +++ b/.github/workflows/test_hooks.yml @@ -20,6 +20,8 @@ jobs: uses: actions/checkout@v4 - name: Test action step uses: ./ # Uses an action in the root directory + env: + MY_VAR: "bar" with: github_token: ${{ secrets.GITHUB_TOKEN }} source_repo_path: AndreasAugustin/template.git diff --git a/README.md b/README.md index 65e29a90..f9d0d82b 100644 --- a/README.md +++ b/README.md @@ -374,6 +374,23 @@ E.q. for the installation phase you need to use commands like `apk add --update Schema and example for the `templatesync.yml` +**Remark** It is possible to use environment variables within the github action definition usable within the command configuration, e.g. + +```yml +- name: Test action step + uses: AndreasAugustin/actions-template-sync@v1 + env: + MY_VAR: "foo" # possible to define envrionment variables + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + source_repo_path: AndreasAugustin/template.git + upstream_branch: main + is_dry_run: true + is_allow_hooks: true +``` + +Please not the double quotes within the following `prepull echo` command + ```yml hooks: install: @@ -382,7 +399,7 @@ hooks: - python3 --version prepull: commands: - - echo 'hi, we are within the prepull phase' + - echo "hi, we are within the prepull phase ${MY_VAR}" - echo 'maybe you want to do adjustments on the local code' precommit: commands: diff --git a/src/sync_common.sh b/src/sync_common.sh index e8abc366..7d290366 100755 --- a/src/sync_common.sh +++ b/src/sync_common.sh @@ -62,6 +62,6 @@ function cmd_from_yml_file() { fi readarray cmd_Arr < <(yq "${YML_PATH} | .[]" "${FILE_NAME}") - for key in "${cmd_Arr[@]}"; do printf '%s\n' "$(${key})"; done + for key in "${cmd_Arr[@]}"; do echo "${key}" | bash; done fi } diff --git a/templatesync.yml b/templatesync.yml index ae3409d5..f8eb2ec9 100644 --- a/templatesync.yml +++ b/templatesync.yml @@ -3,6 +3,7 @@ hooks: install: commands: + - echo "foo ${MY_VAR}" - echo 'hi, we are within the prepush phase' prepush: