e37904a377
The Gitea Contents API returned HTTP error (curl exit 22) when the CI tried to update artifacthub-pkg.yml. Switch to using git checkout/commit/push which reuses the auth already configured by actions/checkout. Also added fetch-depth: 0 so the main branch is available for checkout. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
95 lines
3.9 KiB
YAML
95 lines
3.9 KiB
YAML
name: Release
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- 'v*'
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
container: node:20
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Install dependencies
|
|
run: npm ci
|
|
|
|
- name: Build plugin
|
|
run: npx @kinvolk/headlamp-plugin build
|
|
|
|
- name: Package tarball
|
|
run: npx @kinvolk/headlamp-plugin package
|
|
|
|
- name: Compute tarball checksum
|
|
run: |
|
|
TARBALL=$(ls *.tar.gz)
|
|
CHECKSUM=$(sha256sum "$TARBALL" | awk '{print $1}')
|
|
echo "TARBALL=$TARBALL" >> $GITHUB_ENV
|
|
echo "CHECKSUM=$CHECKSUM" >> $GITHUB_ENV
|
|
echo "Tarball: $TARBALL"
|
|
echo "Checksum: sha256:$CHECKSUM"
|
|
|
|
- name: Update artifacthub-pkg.yml on main
|
|
run: |
|
|
VERSION=${GITHUB_REF_NAME#v}
|
|
git checkout main
|
|
sed -i "s|headlamp/plugin/archive-checksum:.*|headlamp/plugin/archive-checksum: sha256:${CHECKSUM}|" artifacthub-pkg.yml
|
|
sed -i "s|headlamp/plugin/archive-url:.*|headlamp/plugin/archive-url: \"https://github.com/cpfarhood/polaris-headlamp-plugin/releases/download/${GITHUB_REF_NAME}/polaris-headlamp-plugin-${VERSION}.tar.gz\"|" artifacthub-pkg.yml
|
|
sed -i "s|^version:.*|version: ${VERSION}|" artifacthub-pkg.yml
|
|
git config user.name "gitea-actions[bot]"
|
|
git config user.email "gitea-actions[bot]@git.farh.net"
|
|
git add artifacthub-pkg.yml
|
|
git diff --cached --quiet || {
|
|
git commit -m "ci: update artifact hub metadata for ${GITHUB_REF_NAME}"
|
|
git push origin main
|
|
}
|
|
|
|
- name: Install Docker CLI
|
|
run: apt-get update && apt-get install -y docker.io
|
|
|
|
- name: Build Docker image
|
|
run: docker build -t git.farh.net/${{ github.repository }}:${{ github.ref_name }} -t git.farh.net/${{ github.repository }}:latest .
|
|
|
|
- name: Push Docker image
|
|
run: |
|
|
echo "${{ secrets.REGISTRY_TOKEN }}" | docker login git.farh.net -u ${{ github.actor }} --password-stdin
|
|
docker push git.farh.net/${{ github.repository }}:${{ github.ref_name }}
|
|
docker push git.farh.net/${{ github.repository }}:latest
|
|
|
|
- name: Create Gitea release
|
|
uses: akkuman/gitea-release-action@v1
|
|
with:
|
|
files: |
|
|
*.tar.gz
|
|
token: ${{ github.token }}
|
|
|
|
- name: Create GitHub release
|
|
continue-on-error: true
|
|
run: |
|
|
RELEASE_RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
|
|
-H "Authorization: token ${{ secrets.GH_PAT }}" \
|
|
-H "Accept: application/vnd.github+json" \
|
|
"https://api.github.com/repos/cpfarhood/polaris-headlamp-plugin/releases" \
|
|
-d "{\"tag_name\":\"${GITHUB_REF_NAME}\",\"name\":\"${GITHUB_REF_NAME}\",\"generate_release_notes\":true}")
|
|
HTTP_CODE=$(echo "$RELEASE_RESPONSE" | tail -1)
|
|
BODY=$(echo "$RELEASE_RESPONSE" | sed '$d')
|
|
if [ "$HTTP_CODE" = "422" ]; then
|
|
echo "Release already exists, fetching it..."
|
|
BODY=$(curl -sf \
|
|
-H "Authorization: token ${{ secrets.GH_PAT }}" \
|
|
-H "Accept: application/vnd.github+json" \
|
|
"https://api.github.com/repos/cpfarhood/polaris-headlamp-plugin/releases/tags/${GITHUB_REF_NAME}")
|
|
fi
|
|
RELEASE_ID=$(echo "$BODY" | node -e "process.stdin.resume();let d='';process.stdin.on('data',c=>d+=c);process.stdin.on('end',()=>console.log(JSON.parse(d).id))")
|
|
echo "Release ID: $RELEASE_ID"
|
|
curl -sf -X POST \
|
|
-H "Authorization: token ${{ secrets.GH_PAT }}" \
|
|
-H "Content-Type: application/gzip" \
|
|
"https://uploads.github.com/repos/cpfarhood/polaris-headlamp-plugin/releases/${RELEASE_ID}/assets?name=${TARBALL}" \
|
|
--data-binary "@${TARBALL}"
|
|
echo "GitHub release created with same tarball (checksum guaranteed to match)"
|