Update release-zips.yml #14
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: "🚀 Generate Examples Zips and Create Release" | |
on: | |
push: | |
branches: | |
- trunk # Or your default branch | |
workflow_dispatch: | |
jobs: | |
zip-packages: | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# Set up Node.js and install dependencies | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '16' # Use your preferred Node.js version | |
- uses: pnpm/action-setup@v4 | |
with: | |
version: 8.7.1 | |
- name: Install dependencies | |
run: pnpm install | |
# Create zips directory | |
- name: Create zips directory | |
run: mkdir -p zips | |
# Run the plugin-zip script to generate zip files | |
- name: Generate zip files | |
run: | | |
npm run deploy | |
ls -la zips/ # Debug: List contents of zips directory | |
# Install GitHub CLI | |
- name: Install GitHub CLI | |
run: sudo apt-get install -y gh | |
# Authenticate with GitHub CLI | |
- name: Authenticate GitHub CLI | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: gh auth setup-git -h github.com | |
# Create GitHub Release | |
- name: Create GitHub Release | |
id: create_release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# Create a dated tag for version tracking | |
RELEASE_TAG="v$(date +'%Y%m%d%H%M%S')" | |
echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_ENV | |
# Create the new release | |
gh release create $RELEASE_TAG \ | |
--title "Release $RELEASE_TAG" \ | |
--notes "This release contains the latest package zips." | |
# Upload the zips to the Release with consistent names | |
- name: Upload Zips to Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
for file in zips/*.zip; do | |
[ -e "$file" ] || continue | |
# Extract the base name without path and extension | |
filename=$(basename "$file") | |
# Upload to the versioned release | |
gh release upload "${{ env.RELEASE_TAG }}" "$file" | |
done | |
- name: Update or Create Latest Release | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# Check if the latest release exists | |
if gh release view latest; then | |
# Update the existing release instead of deleting | |
gh release edit latest \ | |
--title "Latest Release" \ | |
--notes "This is always the latest release. For permanent links, use the dated releases." \ | |
--latest | |
else | |
# Create the latest release if it doesn't exist | |
gh release create latest \ | |
--title "Latest Release" \ | |
--notes "This is always the latest release. For permanent links, use the dated releases." \ | |
--latest | |
fi | |
# Upload files to the latest release | |
for file in zips/*.zip; do | |
[ -e "$file" ] || continue | |
gh release upload latest "$file" --clobber | |
done |