diff --git a/.gitea/actions/helm-chart-push/README.md b/.gitea/actions/helm-chart-push/README.md new file mode 100644 index 0000000..ae9740d --- /dev/null +++ b/.gitea/actions/helm-chart-push/README.md @@ -0,0 +1,37 @@ +# helm-chart-push + +A Gitea Action for pushing Helm charts to Gitea's built-in Helm registry. This action simplifies the process of publishing Helm charts to your Gitea instance's package registry. + +## Usage + +### Inputs + +| Input | Required | Description | Default | +|-------|----------|-------------|---------| +| `registry-token` | true | The Bearer token for authenticating with the Gitea Helm Registry | - | +| `chart-path` | true | The local path to the Helm chart file (`.tgz` archive) | - | +| `repository-owner` | true | The owner/username of the Gitea Helm Repository | - | +| `gitea-base-url` | false | The base URL of your Gitea instance | `https://gitea.t000-n.de` | + +### Basic Example + +```yaml +name: Push Helm Chart +on: + push: + branches: + - main + +jobs: + push-chart: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: helm package ./charts/my-chart + - name: Push to Gitea Registry + uses: ./.gitea/actions/helm-chart-push + with: + registry-token: ${{ secrets.GITEA_TOKEN }} + chart-path: ./my-chart-*.tgz + repository-owner: ${{ github.repository_owner }} +``` diff --git a/.gitea/actions/helm-chart-push/action.yaml b/.gitea/actions/helm-chart-push/action.yaml new file mode 100644 index 0000000..10655a1 --- /dev/null +++ b/.gitea/actions/helm-chart-push/action.yaml @@ -0,0 +1,96 @@ +name: Push Helm Chart +description: Push a Helm Chart to the Gitea Helm Repository + +inputs: + registry-token: + description: The Bearer token for the Gitea Helm Registry + required: true + chart-path: + description: The path to the Helm Chart (e.g., ./my-chart-1.0.0.tgz) + required: true + repository-owner: + description: The owner of the Gitea Helm Repository + required: true + gitea-base-url: + description: The base URL of the Gitea instance (must include protocol) + required: false + default: "https://gitea.t000-n.de" + chart-name: + description: Optional name for the chart (used for logging and validation) + required: false + timeout: + description: Timeout for the HTTP request in seconds + required: false + default: "60" + +runs: + using: "composite" + steps: + - name: Validate inputs + shell: bash + run: | + # Validate required inputs + if [[ -z "${{ inputs.registry-token }}" ]]; then + echo "Error: registry-token is required" + exit 1 + fi + + if [[ -z "${{ inputs.chart-path }}" ]]; then + echo "Error: chart-path is required" + exit 1 + fi + + if [[ -z "${{ inputs.repository-owner }}" ]]; then + echo "Error: repository-owner is required" + exit 1 + fi + + # Validate chart file exists + if [[ ! -f "${{ inputs.chart-path }}" ]]; then + echo "Error: Chart file not found at path: ${{ inputs.chart-path }}" + exit 1 + fi + + # Validate chart file is a valid tar.gz + if ! tar -tzf "${{ inputs.chart-path }}" >/dev/null 2>&1; then + echo "Error: Invalid chart file format. Must be a valid .tgz file" + exit 1 + fi + + # Validate Gitea base URL format + if [[ ! "${{ inputs.gitea-base-url }}" =~ ^https?:// ]]; then + echo "Error: gitea-base-url must include protocol (http:// or https://)" + exit 1 + fi + + echo "Input validation passed" + + - name: Push Helm Chart + shell: bash + run: | + set -euo pipefail + + # Set variables + CHART_PATH="${{ inputs.chart-path }}" + CHART_NAME="${inputs.chart-name:-$(basename "$CHART_PATH" .tgz)}" + TIMEOUT="${{ inputs.timeout }}" + + echo "Pushing Helm chart: $CHART_NAME" + + # Push chart with proper error handling + RESPONSE=$(curl --fail --show-error \ + --silent \ + --max-time "$TIMEOUT" \ + --header "Authorization: Bearer ${{ inputs.registry-token }}" \ + --header "Content-Type: application/gzip" \ + --header "User-Agent: GitHub-Actions-Helm-Push/1.0" \ + -X POST \ + --upload-file "$CHART_PATH" \ + "${{ inputs.gitea-base-url }}/api/packages/${{ inputs.repository-owner }}/helm/api/charts" \ + 2>&1) || { + echo "Failed to push Helm chart" + echo "Response: $RESPONSE" + exit 1 + } + + echo "Successfully pushed Helm chart: $CHART_NAME" diff --git a/README.md b/README.md index ff24588..6761069 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ # actions -Collection of Gitea friendly actions & workflows \ No newline at end of file +Collection of Gitea friendly actions & workflows. + +* [helm-chart-push](./.gitea/actions/helm-chart-push/README.md) Push a Helm Chart into the Gitea Helm Chart Registry