-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6db8be4
commit ff6000d
Showing
7 changed files
with
97 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Validate user access | ||
|
||
# This callable workflow checks if the workflow is triggered by | ||
# a code owner or an image maintainer by testing the github.actor | ||
# variable against the CODEOWNERS file and the contacts.yaml file | ||
# under oci/* path | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
admin-only: | ||
description: 'The protected workflow should only be triggered as a code owner or an image maintainer' | ||
required: true | ||
default: false | ||
type: boolean | ||
image-path: | ||
description: 'The path to the image to be built' | ||
required: true | ||
type: string | ||
|
||
jobs: | ||
validate-access: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Check if the workflow is triggered by an admin user | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
echo "github.actor: ${{ github.actor }}" | ||
echo "admin-only: ${{ inputs.admin-only }}" | ||
if [[ ${{ inputs.admin-only }} == true ]]; then | ||
echo "Expanding team mentions in the CODEOWNERS file" | ||
teams=$(grep -oE '@[[:alnum:]_.-]+\/[[:alnum:]_.-]+' ${{ github.workspace }}/CODEOWNERS | sort | uniq) | ||
for team in $teams; do | ||
org=$(echo $team | cut -d'/' -f1 | sed 's/@//') | ||
team_name=$(echo $team | cut -d'/' -f2) | ||
members=$(gh api "/orgs/$org/teams/$team_name/members" | jq -r '.[].login') | ||
replacement=$(echo "$members" | xargs -I {} echo -n "@{} " | awk '{$1=$1};1') | ||
sed -i "s|$team|$replacement|g" ${{ github.workspace }}/CODEOWNERS | ||
done | ||
if grep -wq "@${{ github.actor }}" ${{ github.workspace }}/CODEOWNERS; then | ||
echo "The workflow is triggered by ${{ github.actor }} as the code owner" | ||
elif cat ${{ github.workspace }}/${{ inputs.image-path }}/contacts.yaml | yq ".maintainers" | grep "\- " | grep -wq "${{ github.actor }}"; then | ||
echo "The workflow is triggered by ${{ github.actor }} as a maintainer of the image ${{ inputs.image-path }}" | ||
else | ||
echo "The workflow is triggered by a user neither as a code owner nor a maintainer of the image ${{ inputs.image-path }}" | ||
exit 1 | ||
fi | ||
else | ||
echo "The workflow is not restricted to non-code-owner or non-maintainer users" | ||
fi |
Validating CODEOWNERS rules …
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @canonical/rocks |