feat: first release (#49) #50
This file contains hidden or 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
name: Release | |
concurrency: | |
group: release-${{ github.ref_name }}-${{ github.event_name }} | |
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }} | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
identify-changed-projects: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: 'read' | |
actions: 'read' | |
packages: 'write' | |
outputs: | |
matrix: ${{ steps.prepare.outputs.matrix }} | |
length: ${{ steps.prepare.outputs.length }} | |
operator_changed: ${{ steps.check-operator.outputs.changed }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 10 | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: 'pnpm' | |
- name: Cache node_modules | |
uses: actions/cache@v4 | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node_modules- | |
- uses: nrwl/nx-set-shas@v3 | |
with: | |
main-branch-name: 'master' | |
- name: Install dependencies | |
run: pnpm install --frozen-lockfile | |
- name: Identify and filter changed projects | |
id: prepare | |
shell: bash | |
run: | | |
projects=$(npx nx show projects --affected --base=HEAD~1) | |
echo "Changed projects: $projects" | |
whitelisted_projects=("web operator") | |
filtered_projects=() | |
for project in $projects; do | |
if [[ " ${whitelisted_projects[@]} " =~ " ${project} " ]]; then | |
filtered_projects+=("$project") | |
fi | |
done | |
echo "Filtered projects: ${filtered_projects[@]}" | |
if [ ${#filtered_projects[@]} -eq 0 ]; then | |
matrix='[]' | |
else | |
matrix=$(printf "[%s]" "$(printf "\"%s\"," "${filtered_projects[@]}" | sed 's/,$//')") | |
fi | |
echo "matrix=$matrix" >> $GITHUB_OUTPUT | |
echo "length=${#filtered_projects[@]}" >> $GITHUB_OUTPUT | |
- name: Check if operator changed | |
id: check-operator | |
run: | | |
if [[ ${{ steps.prepare.outputs.matrix }} == *"operator"* ]]; then | |
echo "changed=true" >> $GITHUB_OUTPUT | |
else | |
echo "changed=false" >> $GITHUB_OUTPUT | |
fi | |
build-and-push: | |
needs: identify-changed-projects | |
runs-on: ubuntu-latest | |
if: ${{ needs.identify-changed-projects.outputs.length > 0 }} | |
permissions: | |
contents: 'read' | |
packages: 'write' | |
strategy: | |
fail-fast: false | |
matrix: | |
project: ${{ fromJson(needs.identify-changed-projects.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install pnpm | |
uses: pnpm/action-setup@v2 | |
with: | |
version: 10 | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
cache: 'pnpm' | |
- name: Restore node_modules from cache | |
uses: actions/cache@v4 | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/pnpm-lock.json') }} | |
restore-keys: | | |
${{ runner.os }}-node_modules- | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ghcr.io/${{ github.repository }}/${{ matrix.project }} | |
tags: | | |
latest | |
${{ github.sha }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: apps/${{ matrix.project }}/Dockerfile | |
platforms: linux/amd64,linux/arm64 | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
# If the operator project has changed, update the operator image tag in the chart values.yaml | |
release-charts: | |
needs: [identify-changed-projects, build-and-push] | |
if: needs.identify-changed-projects.outputs.operator_changed == 'true' | |
permissions: | |
contents: write | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.PAT }} | |
- name: Install yq | |
run: | | |
wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/local/bin/yq | |
chmod +x /usr/local/bin/yq | |
- name: Configure Git | |
run: | | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "[email protected]" | |
- name: Update Chart Values | |
run: | | |
# Update the operator image tag in values.yaml | |
yq -i '.global.images.operator.tag = "${{ github.sha }}"' k8s/charts/operator/values.yaml | |
# Commit and push changes | |
git add k8s/charts/operator/values.yaml | |
git commit -m "chore: update operator image tag to ${{ github.sha }}" | |
git push | |
- name: Install Helm | |
uses: azure/setup-helm@v4 | |
env: | |
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' | |
- name: Add repositories | |
run: | | |
for dir in $(ls -d k8s/charts/*/); do | |
helm dependency list $dir 2> /dev/null | tail +2 | head -n -1 | awk '{ print "helm repo add " $1 " " $3 }' | while read cmd; do $cmd; done | |
done | |
- name: Build chart dependencies | |
run: | | |
for dir in k8s/charts/*/ | |
do | |
(cd ${dir}; helm dependency build) | |
done | |
- name: Run chart-releaser | |
uses: helm/[email protected] | |
with: | |
charts_dir: k8s/charts | |
config: './.github/configs/cr.yaml' | |
env: | |
CR_TOKEN: '${{ secrets.GITHUB_TOKEN }}' | |
CR_SKIP_EXISTING: true |