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: Create or Update Release from Manifest | |
on: | |
push: | |
branches: | |
- Master | |
paths: | |
- "bin/**" | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "16" | |
- name: Extract version from manifest.json | |
id: get_version | |
run: | | |
VERSION=$(jq -r '.version' manifest.json) | |
echo "Extracted version: $VERSION" | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Find the zip file in bin | |
id: find_zip | |
run: | | |
ZIP_FILE=$(find ./bin -type f -name "*.zip") | |
ZIP_BASENAME=$(basename "$ZIP_FILE") | |
echo "Found zip file: $ZIP_FILE" | |
echo "ZIP_FILE=$ZIP_FILE" >> $GITHUB_ENV | |
echo "ZIP_BASENAME=$ZIP_BASENAME" >> $GITHUB_ENV # Save the zip file's name without the path | |
- name: Check for existing release | |
id: check_release | |
run: | | |
RELEASE_NAME="Extension @${{ env.VERSION }}" | |
echo "Checking for existing release: $RELEASE_NAME" | |
# Check the release using the tag name (formatted correctly) | |
RELEASE=$(gh release view "${{ env.VERSION }}" --json tagName --jq '.tagName' || echo "") | |
if [ "$RELEASE" == "${{ env.VERSION }}" ]; then | |
echo "Existing release found: $RELEASE" | |
echo "RELEASE_EXISTS=true" >> $GITHUB_ENV | |
else | |
echo "No existing release found." | |
echo "RELEASE_EXISTS=false" >> $GITHUB_ENV | |
fi | |
- name: Delete old zip asset if it exists | |
if: env.RELEASE_EXISTS == 'true' | |
run: | | |
ASSET_ID=$(gh release view "${{ env.VERSION }}" --json assets --jq '.assets[] | select(.name == "${{ env.ZIP_BASENAME }}") | .id') | |
if [ -n "$ASSET_ID" ]; then | |
echo "Deleting old asset: $ASSET_ID" | |
gh api repos/:owner/:repo/releases/assets/$ASSET_ID -X DELETE | |
else | |
echo "No old asset found to delete." | |
fi | |
- name: Create or update GitHub Release | |
id: create_or_update_release | |
uses: softprops/action-gh-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: "${{ env.VERSION }}" | |
name: Extension @${{ env.VERSION }} | |
body: "Release created/updated with version ${{ env.VERSION }}" | |
draft: false | |
prerelease: false | |
overwrite: true # Overwrite the release if it exists | |
- name: Attach new zip file to release | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_or_update_release.outputs.upload_url }} | |
asset_path: ${{ env.ZIP_FILE }} # Full path to the zip file | |
asset_name: ${{ env.ZIP_BASENAME }} # Use the same zip file name | |
asset_content_type: application/zip |