Fix: Update GitHub Actions workflow with correct environment variable… #5
This file contains 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: CI/CD Pipeline for Development Release. | |
on: | |
push: | |
branches: [main] | |
workflow_dispatch: | |
permissions: | |
contents: write | |
packages: write | |
checks: write | |
pull-requests: write | |
jobs: | |
test: | |
uses: ./.github/workflows/test.yml | |
release-dev: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Setup Node.js environment | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20.15.1 | |
# Cache root dependencies - only reuse if package-lock.json exactly matches | |
- name: Cache root dependencies | |
uses: actions/cache@v4 | |
id: root-cache | |
with: | |
path: node_modules | |
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }} | |
# Cache webview-ui dependencies - only reuse if package-lock.json exactly matches | |
- name: Cache webview-ui dependencies | |
uses: actions/cache@v4 | |
id: webview-cache | |
with: | |
path: webview-ui/node_modules | |
key: ${{ runner.os }}-npm-webview-${{ hashFiles('webview-ui/package-lock.json') }} | |
- name: Install root dependencies | |
if: steps.root-cache.outputs.cache-hit != 'true' | |
run: npm ci | |
- name: Install webview-ui dependencies | |
if: steps.webview-cache.outputs.cache-hit != 'true' | |
run: cd webview-ui && npm ci | |
- name: Build package | |
run: | | |
# Set the package name and version from package.json or use default values | |
PACKAGE_NAME="$(node -p "require('./package.json').name || 'hai-build-code-generator'")" | |
BUILD_VERSION="$(node -p "require('./package.json').version || '0.0.0'")" | |
# Save the environment variables to GitHub Actions environment | |
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV | |
echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV | |
# Build the VSIX package | |
echo "Output Package Name: $PACKAGE_NAME-$BUILD_VERSION.vsix" | |
npx @vscode/vsce package --out "$PACKAGE_NAME-$BUILD_VERSION.vsix" | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: "${{ env.PACKAGE_NAME }}-${{ env.BUILD_VERSION }}" | |
path: "${{ env.PACKAGE_NAME }}-${{ env.BUILD_VERSION }}.vsix" | |
retention-days: 90 | |
- name: Notify release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NOTIFICATION_URL: ${{ secrets.NOTIFICATION_URL }} | |
run: | | |
ARTIFACT_ID=$(gh api repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts --header "authorization: Bearer $GITHUB_TOKEN" | jq -r '.artifacts[0].id') | |
if [[ -z "$ARTIFACT_ID" || "$ARTIFACT_ID" == "null" ]]; then | |
echo "❌ ERROR: ARTIFACT_ID is missing or invalid." | |
exit 1 | |
fi | |
ARTIFACT_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${ARTIFACT_ID}" | |
echo "✅ Artifact URL: $ARTIFACT_URL" | |
if [[ -z "$NOTIFICATION_URL" ]]; then | |
echo "❌ ERROR: NOTIFICATION_URL is not set." | |
exit 1 | |
fi | |
# Fetch random celebration GIF | |
RANDOM_GIF=$(curl -s "https://api.giphy.com/v1/gifs/random?api_key=0UTRbFtkMxAplrohufYco5IY74U8hOes&tag=celebration+sports&rating=g" | jq -r '.data.images.original.webp') | |
echo "Notifying release ${{ needs.initialize.outputs.package_name }}:${{ needs.initialize.outputs.build_version }}" | |
# Prepare the notification with UI components | |
curl -X POST -H 'Content-type: application/json' --data "{ | |
\"type\": \"message\", | |
\"attachments\": [ | |
{ | |
\"contentType\": \"application/vnd.microsoft.card.adaptive\", | |
\"content\": { | |
\"type\": \"AdaptiveCard\", | |
\"version\": \"1.5\", | |
\"body\": [ | |
{ | |
\"type\": \"ColumnSet\", | |
\"columns\": [ | |
{ | |
\"type\": \"Column\", | |
\"width\": \"auto\", | |
\"items\": [ | |
{ | |
\"type\": \"Icon\", | |
\"name\": \"Megaphone\", | |
\"size\": \"xxSmall\", | |
\"color\": \"Accent\", | |
\"style\": \"Filled\" | |
} | |
] | |
}, | |
{ | |
\"type\": \"Column\", | |
\"width\": \"stretch\", | |
\"items\": [ | |
{ | |
\"type\": \"TextBlock\", | |
\"text\": \"Release Announcement\", | |
\"size\": \"Small\", | |
\"isSubtle\": true | |
} | |
] | |
} | |
] | |
}, | |
{ | |
\"type\": \"TextBlock\", | |
\"text\": \"Release - v${{ env.BUILD_VERSION }}\", | |
\"weight\": \"Bolder\", | |
\"size\": \"Medium\" | |
}, | |
{ | |
\"type\": \"TextBlock\", | |
\"text\": \"🎉 The latest release is now available!\", | |
\"wrap\": true | |
}, | |
{ | |
\"type\": \"Image\", | |
\"url\": \"$RANDOM_GIF\", | |
\"size\": \"Stretch\" | |
}, | |
{ | |
\"type\": \"ActionSet\", | |
\"actions\": [ | |
{ | |
\"type\": \"Action.OpenUrl\", | |
\"title\": \"Download Artifact\", | |
\"url\": \"$ARTIFACT_URL\", | |
\"iconUrl\": \"icon:ArrowDownload\" | |
} | |
] | |
} | |
] | |
} | |
} | |
] | |
}" $NOTIFICATION_URL |