Skip to content

release-policy

release-policy #985

name: Release Policy
on:
workflow_dispatch:
inputs:
owner:
description: "Owner"
required: true
type: string
repo:
description: "Repository"
required: true
type: string
tag:
description: "Tag to release"
required: true
type: string
policy-working-dir:
description: "Working directory of the policy. Useful for repos with policies in folders"
required: false
default: ""
type: string
chart-dir:
description: "Override the chart directory name (defaults to repo name if not provided)"
required: false
type: string
repository_dispatch:
types: [release-policy]
jobs:
release-policy:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout current repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Extract repository info
id: repo-info
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
echo "owner=${{ github.event.inputs.owner }}" >> $GITHUB_OUTPUT
echo "repo=${{ github.event.inputs.repo }}" >> $GITHUB_OUTPUT
echo "tag=${{ github.event.inputs.tag }}" >> $GITHUB_OUTPUT
echo "policy_working_dir=${{ github.event.inputs.policy-working-dir }}" >> $GITHUB_OUTPUT
if [[ -n "${{ github.event.inputs.chart-dir }}" ]]; then
echo "chart_dir=${{ github.event.inputs.chart-dir }}" >> $GITHUB_OUTPUT
else
echo "chart_dir=${{ github.event.inputs.repo }}" >> $GITHUB_OUTPUT
fi
else
echo "owner=${{ github.event.client_payload.owner }}" >> $GITHUB_OUTPUT
echo "repo=${{ github.event.client_payload.repo }}" >> $GITHUB_OUTPUT
echo "tag=${{ github.event.client_payload.tag }}" >> $GITHUB_OUTPUT
if [[ -n "${{ github.event.client_payload.policy_working_dir }}" ]]; then
echo "policy_working_dir=${{ github.event.client_payload.policy_working_dir }}" >> $GITHUB_OUTPUT
else
echo "policy_working_dir=" >> $GITHUB_OUTPUT
fi
if [[ -n "${{ github.event.client_payload.chart_dir }}" ]]; then
echo "chart_dir=${{ github.event.client_payload.chart_dir }}" >> $GITHUB_OUTPUT
else
echo "chart_dir=${{ github.event.client_payload.repo }}" >> $GITHUB_OUTPUT
fi
fi
- name: Clone source repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: ${{ steps.repo-info.outputs.owner }}/${{ steps.repo-info.outputs.repo }}
ref: ${{ steps.repo-info.outputs.tag }}
path: policy-source
- name: Clone source repository at artifacthub branch
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: ${{ steps.repo-info.outputs.owner }}/${{ steps.repo-info.outputs.repo }}
ref: artifacthub
path: policy-source-artifacthub
- name: Setup Go
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version: "1.26"
- name: Create directory structure
run: |
TARGET_DIR="charts/${{ steps.repo-info.outputs.chart_dir }}"
ROOT_DIR="policy-source"
POLICY_WORKING_DIR="${{ steps.repo-info.outputs.policy_working_dir }}"
if [ -n "$POLICY_WORKING_DIR" ]; then
SOURCE_DIR="$ROOT_DIR/$POLICY_WORKING_DIR"
else
SOURCE_DIR="$ROOT_DIR"
fi
mkdir -p "$TARGET_DIR"
if [ -f "$SOURCE_DIR/README.md" ]; then
cp "$SOURCE_DIR/README.md" "$TARGET_DIR/"
else
echo "::error::README.md file not found in the source repository"
exit 1
fi
if [ -f "policy-source/LICENSE" ]; then
cp "policy-source/LICENSE" "$TARGET_DIR/"
else
if [ -f "$ROOT_DIR/LICENSE" ]; then
cp "$ROOT_DIR/LICENSE" "$TARGET_DIR/"
else
echo "::error::LICENSE file not found neither in the source nor the root repository"
exit 1
fi
fi
if [ -f "$SOURCE_DIR/questions-ui.yml" ]; then
cp "$SOURCE_DIR/questions-ui.yml" "$TARGET_DIR/questions.yaml"
else
echo "::notice::questions-ui.yml file not found in the source repository"
fi
- name: Generate Chart.yaml
run: |
TARGET_DIR="charts/${{ steps.repo-info.outputs.chart_dir }}"
POLICY_WORKING_DIR="${{ steps.repo-info.outputs.policy_working_dir }}"
SOURCE_DIR="policy-source-artifacthub"
if [[ -n "$POLICY_WORKING_DIR" ]]; then
SOURCE_DIR="$SOURCE_DIR/$POLICY_WORKING_DIR"
fi
cd pkg2chart
go run main.go \
--pkg "../$SOURCE_DIR/artifacthub-pkg.yml" \
--repo "../policy-source/artifacthub-repo.yml" \
--output "../$TARGET_DIR"
- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TITLE="chore: update policy ${{ steps.repo-info.outputs.repo }} to ${{ steps.repo-info.outputs.tag }}"
BODY="Updates policy ${{ steps.repo-info.outputs.repo }} to ${{ steps.repo-info.outputs.tag }}"
COMMIT_MSG="chore: update policy ${{ steps.repo-info.outputs.repo }} to ${{ steps.repo-info.outputs.tag }}"
TARGET_DIR="charts"
BRANCH_NAME="update-policy-${{ steps.repo-info.outputs.repo }}-${{ steps.repo-info.outputs.tag }}"
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
git checkout -b "$BRANCH_NAME"
git add "$TARGET_DIR"
git commit -m "$COMMIT_MSG"
git push origin "$BRANCH_NAME"
gh pr create \
--title "$TITLE" \
--body "$BODY" \
--base main \
--head "$BRANCH_NAME"