name: Update Docker Image Tags and Release Helm Chart on: schedule: - cron: '0 3 * * 1' # 毎週月曜日 3:00 AM (JST 12:00 PM) workflow_dispatch: env: REGISTRY_URL: https://git.cafepieters.com OWNER: helmchart jobs: update-and-release: runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v3 with: fetch-depth: 0 - name: Install Helm uses: azure/setup-helm@v3 with: version: 'v3.12.0' - name: Check jq availability run: | if ! command -v jq &> /dev/null; then echo "Installing jq..." apt-get update && apt-get install -y jq fi jq --version - name: Check for new n8n version id: n8n run: | set -e echo "Checking n8n versions..." CURRENT=$(grep "tag:" values.yaml | head -1 | sed 's/.*tag: *"\([^"]*\)".*/\1/' | tr -d ' ') echo "Current n8n: $CURRENT" LATEST=$(curl -s "https://registry.hub.docker.com/v2/repositories/n8nio/n8n/tags?page_size=100" | \ jq -r '.results[].name' | \ grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | \ sort -V | tail -1) if [ -z "$LATEST" ]; then echo "Warning: Could not fetch latest n8n version, using current" LATEST="$CURRENT" fi echo "Latest n8n: $LATEST" echo "current=$CURRENT" >> $GITHUB_OUTPUT echo "latest=$LATEST" >> $GITHUB_OUTPUT - name: Determine update and release conditions id: check_update run: | set -e N8N_CURRENT="${{ steps.n8n.outputs.current }}" N8N_LATEST="${{ steps.n8n.outputs.latest }}" echo "n8n: $N8N_CURRENT vs $N8N_LATEST" UPDATE_NEEDED=false RELEASE_NEEDED=false if [ "$N8N_CURRENT" != "$N8N_LATEST" ]; then UPDATE_NEEDED=true RELEASE_NEEDED=true echo "Update and release needed" else echo "Already up to date" fi echo "update_needed=$UPDATE_NEEDED" >> $GITHUB_OUTPUT echo "release_needed=$RELEASE_NEEDED" >> $GITHUB_OUTPUT - name: Update values.yaml if: steps.check_update.outputs.update_needed == 'true' run: | set -e echo "Updating values.yaml..." N8N_OLD="${{ steps.n8n.outputs.current }}" N8N_NEW="${{ steps.n8n.outputs.latest }}" sed -i "s/tag: \"${N8N_OLD}\"/tag: \"${N8N_NEW}\"/" values.yaml echo "n8n updated: $N8N_OLD -> $N8N_NEW" echo "values.yaml updated" git diff values.yaml - name: Update Chart.yaml version if: steps.check_update.outputs.release_needed == 'true' run: | set -e APP_VERSION="${{ steps.n8n.outputs.latest }}" sed -i "s/^version: .*/version: \"$APP_VERSION\"/" Chart.yaml sed -i "s/^appVersion: .*/appVersion: \"$APP_VERSION\"/" Chart.yaml echo "Chart.yaml updated to version $APP_VERSION" cat Chart.yaml - name: Commit changes if: steps.check_update.outputs.update_needed == 'true' run: | git config user.name "Claude" git config user.email "claude@cafepieters.com" git add values.yaml Chart.yaml git commit -m "chore: update n8n to ${{ steps.n8n.outputs.latest }}" git push origin main - name: Package Helm Chart if: steps.check_update.outputs.release_needed == 'true' run: | helm package . echo "Helm chart packaged" - name: Create Git Tag if: steps.check_update.outputs.release_needed == 'true' run: | APP_VERSION="${{ steps.n8n.outputs.latest }}" if git rev-parse "v$APP_VERSION" >/dev/null 2>&1; then echo "Tag v$APP_VERSION already exists, skipping" else git tag -a "v$APP_VERSION" -m "Release n8n $APP_VERSION" git push origin "v$APP_VERSION" echo "Git tag v$APP_VERSION created" fi - name: Create Gitea Release if: steps.check_update.outputs.release_needed == 'true' env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} run: | APP_VERSION="${{ steps.n8n.outputs.latest }}" CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}') PACKAGE_FILE="${CHART_NAME}-${APP_VERSION}.tgz" RELEASE_BODY="n8n Helm Chart v${APP_VERSION} - n8n: ${{ steps.n8n.outputs.latest }}" EXISTING=$(curl -s \ -H "Authorization: token ${GITEA_TOKEN}" \ "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/tags/v${APP_VERSION}" | jq -r '.id // empty') if [ -n "$EXISTING" ]; then echo "Release v$APP_VERSION already exists (id=$EXISTING), skipping" else RELEASE_ID=$(curl -s -X POST \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/json" \ -d "{\"tag_name\":\"v${APP_VERSION}\",\"name\":\"v${APP_VERSION}\",\"body\":\"${RELEASE_BODY}\"}" \ "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases" | jq -r '.id') curl -X POST \ -H "Authorization: token ${GITEA_TOKEN}" \ -H "Content-Type: application/gzip" \ --data-binary "@${PACKAGE_FILE}" \ "${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}/assets?name=${PACKAGE_FILE}" echo "Release v$APP_VERSION created with asset: ${PACKAGE_FILE}" fi - name: Publish to Gitea Package Registry if: steps.check_update.outputs.release_needed == 'true' run: | CHART_NAME=$(grep '^name:' Chart.yaml | awk '{print $2}') APP_VERSION="${{ steps.n8n.outputs.latest }}" PACKAGE_FILE="${CHART_NAME}-${APP_VERSION}.tgz" echo "Publishing ${PACKAGE_FILE} to Gitea Package Registry..." curl --fail-with-body \ -u "${{ secrets.REGISTRY_USER }}:${{ secrets.REGISTRY_TOKEN }}" \ -X POST \ --upload-file "${PACKAGE_FILE}" \ "${REGISTRY_URL}/api/packages/${OWNER}/helm/api/charts" echo "Chart published to registry successfully" - name: Summary run: | APP_VERSION="${{ steps.n8n.outputs.latest }}" UPDATE_NEEDED="${{ steps.check_update.outputs.update_needed }}" RELEASE_NEEDED="${{ steps.check_update.outputs.release_needed }}" echo "========================================" if [ "$UPDATE_NEEDED" = "true" ]; then echo "Update completed!" else echo "Already up to date, no changes." fi echo "========================================" echo "n8n: ${APP_VERSION}" if [ "$RELEASE_NEEDED" = "true" ]; then echo "Chart Version: ${APP_VERSION} (released)" echo "Registry: ${REGISTRY_URL}/api/packages/${OWNER}/helm" else echo "No release needed" fi echo "========================================"