Merge pull request #2 from chifu1234/main #5
Workflow file for this run
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: Headlamp Plugin CI/CD | |
| on: | |
| push: | |
| branches: [main, master] | |
| tags: | |
| - 'v*' | |
| pull_request: | |
| branches: [main, master] | |
| jobs: | |
| test: | |
| name: Lint, Format, Test & Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Lint | |
| run: npx @kinvolk/headlamp-plugin lint . || npm run lint --if-present | |
| - name: Format check | |
| run: npx @kinvolk/headlamp-plugin format --check . || npm run format -- --check --if-present | |
| - name: Type check | |
| run: npx @kinvolk/headlamp-plugin tsc . || npm run tsc --if-present || echo "No type check configured" | |
| - name: Test | |
| run: npx @kinvolk/headlamp-plugin test . || npm test --if-present | |
| - name: Build | |
| run: npx @kinvolk/headlamp-plugin build . || npm run build | |
| release: | |
| name: Release to GitHub + Docker + Artifact Hub | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| needs: test | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| TAG="${{ github.ref_name }}" | |
| VERSION="${TAG#v}" # strip leading 'v' for clean version field | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| - name: Build & Package | |
| id: package | |
| run: | | |
| VERSION="${{ steps.version.outputs.version }}" | |
| npm version "$VERSION" --no-git-tag-version --allow-same-version | |
| npm run build | |
| npm run package | |
| TARBALL=$(ls -1 *.tar.gz | head -n1) | |
| echo "tarball=$TARBALL" >> $GITHUB_OUTPUT | |
| if [ -f "$TARBALL" ]; then | |
| CHECKSUM=$(sha256sum "$TARBALL" | awk '{print $1}') | |
| echo "checksum=$CHECKSUM" >> $GITHUB_OUTPUT | |
| echo "✅ Tarball: $TARBALL" | |
| echo "✅ Checksum: sha256:$CHECKSUM" | |
| else | |
| echo "❌ No tarball found!" | |
| exit 1 | |
| fi | |
| - name: Create GitHub Release + upload asset | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: '*.tar.gz' | |
| tag_name: ${{ steps.version.outputs.tag }} | |
| name: Release ${{ steps.version.outputs.tag }} | |
| generate_release_notes: true | |
| - name: Update artifacthub-pkg.yml (full automation) | |
| run: | | |
| # Install yq (reliable one-liner) | |
| sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 && sudo chmod +x /usr/local/bin/yq | |
| VERSION="${{ steps.version.outputs.version }}" | |
| TAG="${{ steps.version.outputs.tag }}" | |
| TARBALL="${{ steps.package.outputs.tarball }}" | |
| CHECKSUM="${{ steps.package.outputs.checksum }}" | |
| ARCHIVE_URL="https://github.com/${{ github.repository }}/releases/download/${TAG}/${TARBALL}" | |
| yq -i '.version = "'"$VERSION"'"' artifacthub-pkg.yml | |
| yq -i '.createdAt = "'"$(date -u +"%Y-%m-%dT%H:%M:%SZ")"'"' artifacthub-pkg.yml | |
| yq -i '.annotations."headlamp/plugin/archive-url" = "'"$ARCHIVE_URL"'"' artifacthub-pkg.yml | |
| yq -i '.annotations."headlamp/plugin/archive-checksum" = "sha256:'"$CHECKSUM"'"' artifacthub-pkg.yml | |
| echo "✅ artifacthub-pkg.yml updated:" | |
| echo " version: $VERSION" | |
| echo " archive-url: $ARCHIVE_URL" | |
| echo " checksum: sha256:$CHECKSUM" | |
| - name: Commit & push updated artifacthub-pkg.yml to main | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add artifacthub-pkg.yml | |
| git add package.json | |
| git add package-lock.json | |
| git commit -m "chore(release): update artifacthub-pkg.yml/package.json/package-lock.json for ${{ steps.version.outputs.tag }}" || echo "No changes to commit" | |
| git push origin HEAD:main # pushes to your default branch (change to master if needed) | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Build & push Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: true | |
| tags: | | |
| ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ steps.version.outputs.tag }} | |
| ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest |