Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Action to Lint and Publish Charts and tag repo #9

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@ on:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: latest
token: ${{ secrets.GH_OMEC_PAT }}

- name: Find all Charts and Lint them
run: |
for dir in $(find . -maxdepth 1 -mindepth 1 -type d); do
if [[ -f "$dir/Chart.yaml" ]]; then
helm lint "$dir"
fi
done

license-check:
runs-on: ubuntu-latest
steps:
Expand Down
118 changes: 118 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2024 Intel Corporation

name: Tag/Publish Release

on:
push:
branches:
- main

env:
CHARTS_REPO_URL: https://charts.aetherproject.org
CHARTS_DIR: charts
REF_CHARTS_DIR: charts-ref

jobs:
# CAUTION: Other actions depend on this name "tag-github"
tag-github:
runs-on: ubuntu-latest
outputs:
changed: ${{ steps.version-change.outputs.changed }}
version: ${{ steps.version-change.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Get changes
id: version-file
run: |
if git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | grep VERSION; then
echo "changed=true" >> $GITHUB_OUTPUT
else
echo "VERSION file was not changed"
fi

- name: Validate change in version file
id: version-change
if: steps.version-file.outputs.changed == 'true'
run: |
version=$(cat VERSION)
echo "version=$version"
validate="^[0-9]+\.[0-9]+\.[0-9]+$"
if [[ $version =~ $validate ]]; then
echo "changed=true" >> $GITHUB_OUTPUT
echo "version=$version" >> $GITHUB_OUTPUT
else
echo "Version change not for release"
fi

- name: Create release using REST API
if: steps.version-change.outputs.changed == 'true'
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GH_OMEC_PAT }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/releases \
-d '{
"tag_name": "${{ steps.version-change.outputs.version }}",
"target_commitish": "master",
"name": "${{ steps.version-change.outputs.version }}",
"draft": false,
"prerelease": false,
"generate_release_notes": true
}'

publish:
runs-on: ubuntu-latest
needs: tag-github
if: needs.tag-github.outputs.changed == 'true'
steps:
- uses: actions/checkout@v4

- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: latest
token: ${{ secrets.GH_OMEC_PAT }}

- name: Get current Index.yaml
run: |
mkdir -p ${{ env.REF_CHARTS_DIR }}
curl -o ${{ env.REF_CHARTS_DIR }}/index.yaml ${{ env.CHARTS_REPO_URL }}/index.yaml

- name: Find all Charts and Package them
run: |
mkdir -p ${{ env.CHARTS_DIR }}
for dir in $(find . -maxdepth 1 -mindepth 1 -type d); do
if [[ -f "$dir/Chart.yaml" ]]; then
echo "Packaging charts for: $dir"
helm dependency update "$dir"
helm package "$dir" --destination ${{ env.CHARTS_DIR }}
fi
done
helm repo index ${{ env.CHARTS_DIR }} --url ${{ env.CHARTS_REPO_URL }} --merge ${{ env.REF_CHARTS_DIR }}/index.yaml

- name: Remove not "updated" local Charts (version has not changed)
working-directory: ${{ env.CHARTS_DIR }}
run: |
for file in *.tgz; do
if grep -q "${{ env.CHARTS_REPO_URL }}/$file" "../${{ env.REF_CHARTS_DIR }}/index.yaml"; then
echo "Not publishing $file because it is already in ${{ env.CHARTS_REPO_URL }}/index.yaml"
rm $file
fi
done

- name: rsync deployments
uses: burnett01/[email protected]
with:
switches: -avh
path: ${{ env.CHARTS_DIR }}
remote_path: /srv/sites/charts.aetherproject.org/
remote_host: static.opennetworking.org
remote_user: ${{ secrets.JENKINS_USERNAME }}
remote_key: ${{ secrets.JENKINS_SSHKEY }}
remote_key_pass: ${{ secrets.JENKINS_PASSPHRASE }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ requirements.lock

# ignore dependent chart dirs
charts
charts-ref
Chart.lock

# ignore MacOS DS_Store
Expand Down
Loading