Skip to content

Commit

Permalink
Merge branch 'main' into feat/gpg_sign_pwd
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasAugustin committed Feb 29, 2024
2 parents cbc5913 + baac1d8 commit e28f14d
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 13 deletions.
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@
"contributions": [
"review"
]
},
{
"login": "kdeldycke",
"name": "Kevin Deldycke",
"avatar_url": "https://avatars.githubusercontent.com/u/159718?v=4",
"profile": "https://kevin.deldycke.com",
"contributions": [
"bug",
"ideas"
]
}
],
"contributorsPerLine": 7,
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/actions_template_sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_repo_path: AndreasAugustin/template
upstream_branch: main # defaults to main
pr_labels: chore,template-sync,example
pr_labels: chore,📚 template-sync,example
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Test action step
id: test
uses: ./ # Uses an action in the root directory
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
source_repo_path: AndreasAugustin/template.git
is_dry_run: true
- name: print output
env:
FORMER_OUTPUT_PR_BRANCH: ${{ steps.test.outputs.pr_branch }}
run: echo "pr_branch ${FORMER_OUTPUT_PR_BRANCH}"
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
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
# Changelog

## [1.8.0](https://github.com/AndreasAugustin/actions-template-sync/compare/v1.7.0...v1.8.0) (2024-02-29)


### Features

* **#472:** :sparkles: define output ([#473](https://github.com/AndreasAugustin/actions-template-sync/issues/473)) ([a19cd8d](https://github.com/AndreasAugustin/actions-template-sync/commit/a19cd8d7c999cdf9bdc2a08818eb2878d1222cdf))

## [1.7.0](https://github.com/AndreasAugustin/actions-template-sync/compare/v1.6.2...v1.7.0) (2024-02-29)


### Features

* **#468:** :sparkles: enable usage of github env variables within hooks ([#469](https://github.com/AndreasAugustin/actions-template-sync/issues/469)) ([17d4603](https://github.com/AndreasAugustin/actions-template-sync/commit/17d4603da56b49e4b72c6531ba6d2db6dbcc3a31))

## [1.6.2](https://github.com/AndreasAugustin/actions-template-sync/compare/v1.6.1...v1.6.2) (2024-02-25)


### Bug Fixes

* :bug: try catch for edge cases ([#465](https://github.com/AndreasAugustin/actions-template-sync/issues/465)) ([95ce4e4](https://github.com/AndreasAugustin/actions-template-sync/commit/95ce4e4d5cc72b62970056977256a6592a10547c))

## [1.6.1](https://github.com/AndreasAugustin/actions-template-sync/compare/v1.6.0...v1.6.1) (2024-02-25)


### Bug Fixes

* **#461:** :bug: issue with pull request labels with emoji and space ([#462](https://github.com/AndreasAugustin/actions-template-sync/issues/462)) ([89b8d21](https://github.com/AndreasAugustin/actions-template-sync/commit/89b8d210b8454957a81dbbf5b81e6977708a25cd))

## [1.6.0](https://github.com/AndreasAugustin/actions-template-sync/compare/v1.5.0...v1.6.0) (2024-02-22)


Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
######################################
FROM alpine:3.19.1 as dev

ARG GH_CLI_VER=2.34.0
ARG GH_CLI_VER=2.44.1

# install packages
RUN apk add --update --no-cache bash make git zsh curl tmux musl openssh git-lfs vim yq gnupg tig
Expand Down
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# actions-template-sync
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-25-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-26-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

[![actions-template-sync](https://github.com/AndreasAugustin/actions-template-sync/actions/workflows/actions_template_sync.yml/badge.svg)](https://github.com/AndreasAugustin/actions-template-sync/actions/workflows/actions_template_sync.yml)
Expand Down Expand Up @@ -230,7 +230,7 @@ jobs:
source_repo_path: ${{ secrets.SOURCE_REPO_PATH }} # <owner/repo>, should be within secrets
```

### Configuration parameters
### Action Inputs

| Variable | Description | Required | `[Default]` |
|-----------------------------|---------------------------------------------------------------------------------------------------------------|----------|-----------------------------------------------------------------------|
Expand All @@ -255,6 +255,14 @@ jobs:
| gpg_private_key | `[optional]` set if you want to sign commits | `false` | |
| gpg_passphrase | `[optional]` set if your optionial gpg private key has a passphrase | `false` | |

### Action Outputs

> Properties that are available after the action executed.

| output | description |
| ------ | ----------- |
| pr_branch | The name of the branch used for the pull request |

### Docker

There are docker images available. Please checkout [How to use docker](docs/DOCKER.md) for details.
Expand Down Expand Up @@ -375,6 +383,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 @@ -383,7 +408,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 Expand Up @@ -558,6 +583,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="http://www.xontab.com"><img src="https://avatars.githubusercontent.com/u/4987684?v=4?s=100" width="100px;" alt="Shaun Tabone"/><br /><sub><b>Shaun Tabone</b></sub></a><br /><a href="https://github.com/AndreasAugustin/actions-template-sync/commits?author=xontab" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/kevin-aude"><img src="https://avatars.githubusercontent.com/u/98819045?v=4?s=100" width="100px;" alt="Kevin AUDE"/><br /><sub><b>Kevin AUDE</b></sub></a><br /><a href="#ideas-kevin-aude" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/AndreasAugustin/actions-template-sync/commits?author=kevin-aude" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Jnig"><img src="https://avatars.githubusercontent.com/u/3729585?v=4?s=100" width="100px;" alt="Jakob"/><br /><sub><b>Jakob</b></sub></a><br /><a href="https://github.com/AndreasAugustin/actions-template-sync/pulls?q=is%3Apr+reviewed-by%3Ajnig" title="Reviewed Pull Requests">👀</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://kevin.deldycke.com"><img src="https://avatars.githubusercontent.com/u/159718?v=4?s=100" width="100px;" alt="Kevin Deldycke"/><br /><sub><b>Kevin Deldycke</b></sub></a><br /><a href="https://github.com/AndreasAugustin/actions-template-sync/issues?q=author%3Akdeldycke" title="Bug reports">🐛</a> <a href="#ideas-kdeldycke" title="Ideas, Planning, & Feedback">🤔</a></td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion src/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM alpine:3.19.1

ARG GH_CLI_VER=2.34.0
ARG GH_CLI_VER=2.44.1

# TODO(anau) change user
ARG GITHUB_URL="https://github.com/AndreasAugustin/actions-template-sync"
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
}
28 changes: 22 additions & 6 deletions src/sync_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,20 +178,23 @@ echo "::endgroup::"


function maybe_create_labels () {
all_labels=${PR_LABELS//,/$'\n'}
for label in $all_labels
readarray -t labels_array < <(awk -F',' '{ for( i=1; i<=NF; i++ ) print $i }' <<<"${PR_LABELS}")
for label in "${labels_array[@]}"
do
search_result=$(gh label list \
--search "${label}" \
--limit 1 \
--json name \
--template '{{range .}}{{printf "%v" .name}}{{"\n"}}{{end}}')

if [ "${search_result}" = "${label}" ]; then
info "label '${label}' was found in the repository"
if [ "${search_result}" = "${label##[[:space:]]}" ]; then
info "label '${label##[[:space:]]}' was found in the repository"
else
gh label create "${label}"
info "label '${label}' was missing and has been created"
if gh label create "${label}"; then
info "label '${label}' was missing and has been created"
else
warn "label creation did not work. For any reason the former check sometimes is failing"
fi
fi
done
}
Expand Down Expand Up @@ -236,3 +239,16 @@ else
fi

echo "::endgroup::"

function set_github_action_outputs() {
echo "::group::set gh action outputs"
if [[ -z "${GITHUB_RUN_ID}" ]]; then
info "env var 'GITHUB_RUN_ID' is empty -> no github action workflow"
else
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter
echo "pr_branch=${NEW_BRANCH}" >> "$GITHUB_OUTPUT"
fi
echo "::endgroup::"
}

set_github_action_outputs
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 e28f14d

Please sign in to comment.