diff --git a/.github/workflows/release-pullrequest.yaml b/.github/workflows/release-pullrequest.yaml index 392eb1b..2e09487 100644 --- a/.github/workflows/release-pullrequest.yaml +++ b/.github/workflows/release-pullrequest.yaml @@ -10,14 +10,66 @@ jobs: runs-on: ubuntu-latest steps: + - name: Extract and Store Trimmed Repository Name + run: | + REPO_CHART_NAME="${{ github.repository }}" + REPO_APP_NAME=$(echo "$REPO_CHART_NAME" | sed 's/-chart$//') # Remove "-chart" suffix if present + + # Check if the trimmed repo exists + HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/$REPO_APP_NAME") + + if [[ "$HTTP_STATUS" -eq 200 ]]; then + echo "Using trimmed repository name: $REPO_APP_NAME" + echo "REPO_APP_NAME=$REPO_APP_NAME" >> $GITHUB_ENV + else + echo "Trimmed repository not found. Falling back to original repository name." + echo "REPO_APP_NAME=$REPO_CHART_NAME" >> $GITHUB_ENV + fi + + - name: Use the Stored Variable + run: | + echo "Trimmed Repository Name: ${{ env.REPO_APP_NAME }}" + + - name: Authenticate with GitHub App + id: authenticate + uses: tibdex/github-app-token@v1 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.PRIVATE_KEY }} + + - name: Extract latest App Version + uses: tdemin/find-latest-tag@v1 + id: app_version + with: + repo: https://${{ steps.authenticate.outputs.token }}@github.com/${{ env.REPO_APP_NAME }}.git + + - name: Extract latest Chart Version + uses: tdemin/find-latest-tag@v1 + id: chart_version + with: + repo: https://${{ steps.authenticate.outputs.token }}@github.com/${{ github.repository }}.git + - name: Checkout uses: actions/checkout@v3 + - name: Print Version + run: | + echo APP_VERSION:${{steps.app_version.outputs.tag}} + echo CHART_VERSION:${{steps.chart_version.outputs.tag}} + - name: Replace Version in Chart.yaml - run: sed -i 's/CHART_VERSION/0.0.1/g' ./chart/Chart.yaml + run: sed -i 's/CHART_VERSION/${{ steps.chart_version.outputs.tag }}/g' ./chart/Chart.yaml + + - name: Print latest App Version + run: echo ${{ steps.app_version.outputs.tag }} + + - name: Replace App Version in Chart.yaml + run: sed -i 's/APP_VERSION/${{ steps.app_version.outputs.tag }}/g' ./chart/Chart.yaml - name: Set up Helm uses: azure/setup-helm@v4.1.0 - name: Helm lint - run: helm lint ./chart + run: helm lint ./chart \ No newline at end of file diff --git a/.github/workflows/release-tag.yaml b/.github/workflows/release-tag.yaml index 4a349ed..45f77b4 100644 --- a/.github/workflows/release-tag.yaml +++ b/.github/workflows/release-tag.yaml @@ -9,27 +9,70 @@ jobs: runs-on: ubuntu-latest steps: + - name: Extract and Store Trimmed Repository Name + run: | + REPO_CHART_NAME="${{ github.repository }}" + REPO_APP_NAME=$(echo "$REPO_CHART_NAME" | sed 's/-chart$//') # Remove "-chart" suffix if present + + # Check if the trimmed repo exists + HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/$REPO_APP_NAME") + + if [[ "$HTTP_STATUS" -eq 200 ]]; then + echo "Using trimmed repository name: $REPO_APP_NAME" + echo "REPO_APP_NAME=$REPO_APP_NAME" >> $GITHUB_ENV + else + echo "Trimmed repository not found. Falling back to original repository name." + echo "REPO_APP_NAME=$REPO_CHART_NAME" >> $GITHUB_ENV + fi + + - name: Use the Stored Variable + run: | + echo "Trimmed Repository Name: ${{ env.REPO_APP_NAME }}" + + - name: Authenticate with GitHub App + id: authenticate + uses: tibdex/github-app-token@v1 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.PRIVATE_KEY }} + + - name: Extract latest App Version + uses: tdemin/find-latest-tag@v1 + id: app_version + with: + repo: https://${{ steps.authenticate.outputs.token }}@github.com/${{ env.REPO_APP_NAME }}.git + + - name: Extract latest Chart Version + uses: tdemin/find-latest-tag@v1 + id: chart_version + with: + repo: https://${{ steps.authenticate.outputs.token }}@github.com/${{ github.repository }}.git + - name: Checkout uses: actions/checkout@v3 - - name: Extract Version - id: tagger - uses: battila7/get-version-action@v2 - - name: Print Version run: | - echo ${{steps.tagger.outputs.version}} - echo ${{steps.tagger.outputs.version-without-v}} + echo APP_VERSION:${{steps.app_version.outputs.tag}} + echo CHART_VERSION:${{steps.chart_version.outputs.tag}} - name: Replace Version in Chart.yaml - run: sed -i 's/CHART_VERSION/${{ steps.tagger.outputs.version-without-v }}/g' ./chart/Chart.yaml + run: sed -i 's/CHART_VERSION/${{ steps.chart_version.outputs.tag }}/g' ./chart/Chart.yaml + + - name: Print latest App Version + run: echo ${{ steps.app_version.outputs.tag }} + + - name: Replace App Version in Chart.yaml + run: sed -i 's/APP_VERSION/${{ steps.app_version.outputs.tag }}/g' ./chart/Chart.yaml - name: Publish Helm chart uses: stefanprodan/helm-gh-pages@master with: - token: ${{ secrets.HELM_CHARTS_BOT }} + token: ${{ steps.authenticate.outputs.token }} charts_dir: ./ charts_url: https://charts.krateo.io owner: krateoplatformops repository: helm-charts - branch: gh-pages + branch: gh-pages \ No newline at end of file diff --git a/chart/templates/widgets.composition-card.yaml b/chart/templates/widgets.composition-card.yaml index dd12cd5..811d8b5 100644 --- a/chart/templates/widgets.composition-card.yaml +++ b/chart/templates/widgets.composition-card.yaml @@ -6,6 +6,7 @@ metadata: namespace: {{ .Release.Namespace }} data: panel: "false" + route: /compositions/{{ .Release.Namespace }}/{{ .Release.Name }} --- apiVersion: templates.krateo.io/v1alpha1 kind: Widget @@ -32,7 +33,7 @@ spec: verb: DELETE app: template: - tags: {{ .Release.Namespace }} + tags: {{ .Release.Namespace }},{{.Chart.Version}} title: {{ .Release.Name }} content: This is a card for {{ .Release.Name }} composition {{- if and .Values.card .Values.card.icon }} @@ -40,8 +41,10 @@ spec: {{- else }} icon: fa-circle-question {{- end }} - {{- if and .Values.card .Values.card.color }} - color: {{ .Values.card.color }} - {{- else }} - color: grey - {{- end }} + color: ${ .getComposition.status.conditions[] | select(.type == "Ready") | if .status == "False" then "orange" elif .status == "True" then "green" else "grey" end } + status: ${ .getComposition.status.conditions[] | select(.type == "Ready") | "Ready:" + .status } + date: ${ .getComposition.metadata.creationTimestamp } + api: + - name: getComposition + path: "/apis/{{ .Values.global.compositionApiVersion }}/namespaces/{{ .Release.Namespace }}/{{ .Values.global.compositionResource }}/{{ .Release.Name }}" + verb: GET \ No newline at end of file diff --git a/chart/templates/widgets.composition-route.yaml b/chart/templates/widgets.composition-route.yaml new file mode 100644 index 0000000..614c8a2 --- /dev/null +++ b/chart/templates/widgets.composition-route.yaml @@ -0,0 +1,18 @@ +apiVersion: templates.krateo.io/v1alpha1 +kind: Widget +metadata: + name: composition-{{ .Release.Name }}-route + namespace: {{ .Release.Namespace }} +spec: + actions: + - template: + apiVersion: templates.krateo.io/v1alpha1 + name: composition-{{ .Release.Name }}-tablist + namespace: {{ .Release.Namespace }} + resource: collections + verb: GET + app: + template: + menu: "false" + path: /compositions/{{ .Release.Namespace }}/{{ .Release.Name }} + type: route \ No newline at end of file diff --git a/chart/templates/widgets.composition-tabpane-yamlviewer-row-column-1-panel-yamlviewer.yaml b/chart/templates/widgets.composition-tabpane-yamlviewer-row-column-1-panel-yamlviewer.yaml index 5435375..9938fb4 100644 --- a/chart/templates/widgets.composition-tabpane-yamlviewer-row-column-1-panel-yamlviewer.yaml +++ b/chart/templates/widgets.composition-tabpane-yamlviewer-row-column-1-panel-yamlviewer.yaml @@ -8,11 +8,9 @@ spec: type: paragraph app: template: - yaml: {{ .getCompositionYaml }} + json: ${ .getCompositionJSON } api: - - name: getCompositionYaml + - name: getCompositionJSON path: "/apis/{{ .Values.global.compositionApiVersion }}/namespaces/{{ .Release.Namespace }}/{{ .Values.global.compositionResource }}/{{ .Release.Name }}" verb: GET - headers: - - 'Accept: application/yaml' {{- end }} \ No newline at end of file diff --git a/chart/values.yaml b/chart/values.yaml index 9f67caf..9720c24 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -10,7 +10,7 @@ terminal: events: enabled: true yamlviewer: - enabled: false + enabled: true namespace: krateo-system global: compositionId: compositionId