Skip to content

Commit

Permalink
feat(#468): ✨ enable usage of github env variables within hooks (#469)
Browse files Browse the repository at this point in the history
* feat: ✨ hooks support env variables

* feat: ✨

* doc: 📝 add information about using env variables

* feat: ✨ cleanup
  • Loading branch information
AndreasAugustin committed Feb 29, 2024
1 parent 3c41bc1 commit 17d4603
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test_hooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/sync_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
1 change: 1 addition & 0 deletions templatesync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
hooks:
install:
commands:
- echo "foo ${MY_VAR}"
- echo 'hi, we are within the prepush phase'

prepush:
Expand Down

0 comments on commit 17d4603

Please sign in to comment.