cfb35fe73d
actions/checkout v6 was already adopted in headlamp-agent-skills. This brings the org-level reusable workflows (plugin-ci, plugin-release, ci-health-check) up to the same version. Affects all plugin repos that call these shared workflows. Co-Authored-By: Paperclip <noreply@paperclip.ing>
175 lines
6.0 KiB
YAML
175 lines
6.0 KiB
YAML
name: Plugin Release
|
|
|
|
on:
|
|
workflow_call:
|
|
inputs:
|
|
version:
|
|
description: 'Release version (e.g. 1.0.0)'
|
|
required: true
|
|
type: string
|
|
node-version:
|
|
description: 'Node.js version to use'
|
|
required: false
|
|
type: string
|
|
default: '22'
|
|
upstream-repo:
|
|
description: 'Upstream repo to fetch appVersion from (e.g. fenio/tns-csi). Leave empty to skip.'
|
|
required: false
|
|
type: string
|
|
default: ''
|
|
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
|
|
concurrency:
|
|
group: release
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
ci:
|
|
uses: ./.github/workflows/plugin-ci.yaml
|
|
with:
|
|
node-version: ${{ inputs.node-version }}
|
|
|
|
release:
|
|
needs: ci
|
|
runs-on: local-ubuntu-latest
|
|
timeout-minutes: 10
|
|
|
|
steps:
|
|
- name: Validate version format
|
|
run: |
|
|
if [[ ! "${{ inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
echo "Error: Version must be in X.Y.Z format"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Checkout
|
|
uses: actions/checkout@v6
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: ${{ inputs.node-version }}
|
|
cache: 'npm'
|
|
|
|
- name: Check tag does not already exist
|
|
run: |
|
|
if git tag -l "v${{ inputs.version }}" | grep -q "v${{ inputs.version }}"; then
|
|
echo "::error::Tag v${{ inputs.version }} already exists. Skipping duplicate release."
|
|
exit 1
|
|
fi
|
|
|
|
- name: Configure Git
|
|
run: |
|
|
git config --global user.name "github-actions[bot]"
|
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
git config --global --add safe.directory "$GITHUB_WORKSPACE"
|
|
|
|
- name: Update version in package.json
|
|
run: npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version
|
|
|
|
- name: Update artifacthub-pkg.yml
|
|
run: |
|
|
VERSION="${{ inputs.version }}"
|
|
PKG_NAME=$(jq -r .name package.json)
|
|
RELEASE_URL="https://github.com/${{ github.repository }}/releases/download/v${VERSION}/${PKG_NAME}-${VERSION}.tar.gz"
|
|
sed -i "s/^version:.*/version: \"${VERSION}\"/" artifacthub-pkg.yml
|
|
sed -i "s|headlamp/plugin/archive-url:.*|headlamp/plugin/archive-url: \"${RELEASE_URL}\"|" artifacthub-pkg.yml
|
|
|
|
- name: Update appVersion from upstream release
|
|
if: inputs.upstream-repo != ''
|
|
run: |
|
|
APP_VERSION=$(curl -sf "https://api.github.com/repos/${{ inputs.upstream-repo }}/releases/latest" | jq -r '.tag_name | ltrimstr("v")')
|
|
if [ -z "$APP_VERSION" ] || [ "$APP_VERSION" = "null" ]; then
|
|
echo "::warning::Could not fetch latest upstream release, skipping appVersion update"
|
|
else
|
|
sed -i "s|^appVersion:.*|appVersion: \"${APP_VERSION}\"|" artifacthub-pkg.yml
|
|
echo "appVersion set to ${APP_VERSION}"
|
|
fi
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Build plugin
|
|
run: npx @kinvolk/headlamp-plugin build
|
|
|
|
- name: Package plugin
|
|
run: npx @kinvolk/headlamp-plugin package
|
|
|
|
- name: Prepare release tarball
|
|
run: |
|
|
VERSION="${{ inputs.version }}"
|
|
PKG_NAME=$(jq -r .name package.json)
|
|
TARBALL="${PKG_NAME}-${VERSION}.tar.gz"
|
|
# Rename tarball if headlamp-plugin produced a different name
|
|
for f in *.tar.gz; do
|
|
[ "$f" != "$TARBALL" ] && mv "$f" "$TARBALL"
|
|
done
|
|
if [ ! -f "$TARBALL" ]; then
|
|
echo "Error: Expected tarball $TARBALL not found"
|
|
ls -la *.tar.gz 2>/dev/null || echo "No .tar.gz files found"
|
|
exit 1
|
|
fi
|
|
echo "TARBALL=$TARBALL" >> $GITHUB_ENV
|
|
echo "PKG_NAME=$PKG_NAME" >> $GITHUB_ENV
|
|
|
|
- name: Validate tarball
|
|
run: |
|
|
echo "Tarball: ${{ env.TARBALL }}"
|
|
ls -lh "${{ env.TARBALL }}"
|
|
tar -tzf "${{ env.TARBALL }}" | head -20
|
|
tar -tzf "${{ env.TARBALL }}" | grep -q "main.js" || { echo "Error: main.js not found in tarball"; exit 1; }
|
|
|
|
- name: Compute checksum
|
|
run: |
|
|
CHECKSUM=$(sha256sum "${{ env.TARBALL }}" | awk '{print $1}')
|
|
echo "CHECKSUM=$CHECKSUM" >> $GITHUB_ENV
|
|
sed -i "s|headlamp/plugin/archive-checksum:.*|headlamp/plugin/archive-checksum: sha256:${CHECKSUM}|" artifacthub-pkg.yml
|
|
|
|
- name: Commit and tag
|
|
run: |
|
|
VERSION="${{ inputs.version }}"
|
|
BRANCH="release/v${VERSION}"
|
|
git checkout -b "$BRANCH"
|
|
git add package.json package-lock.json artifacthub-pkg.yml
|
|
git commit -m "release: v${VERSION}"
|
|
git tag "v${VERSION}"
|
|
git push origin "$BRANCH" --tags
|
|
|
|
- name: Create GitHub Release
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
tag_name: "v${{ inputs.version }}"
|
|
files: ${{ env.TARBALL }}
|
|
fail_on_unmatched_files: true
|
|
generate_release_notes: true
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Install GitHub CLI
|
|
run: |
|
|
if ! command -v gh &>/dev/null; then
|
|
GH_VERSION="2.74.0"
|
|
curl -fsSL "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_amd64.tar.gz" -o /tmp/gh.tar.gz
|
|
tar -xzf /tmp/gh.tar.gz -C /tmp
|
|
mv "/tmp/gh_${GH_VERSION}_linux_amd64/bin/gh" /usr/local/bin/gh
|
|
rm -rf /tmp/gh.tar.gz "/tmp/gh_${GH_VERSION}_linux_amd64"
|
|
gh --version
|
|
fi
|
|
|
|
- name: Create PR for version bump
|
|
run: |
|
|
VERSION="${{ inputs.version }}"
|
|
gh pr create \
|
|
--title "release: v${VERSION}" \
|
|
--body "Automated version bump and checksum update for v${VERSION}." \
|
|
--base main \
|
|
--head "release/v${VERSION}"
|
|
gh pr merge "release/v${VERSION}" --auto --squash --delete-branch
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|