Skip to content

CI: adjust release params #21

CI: adjust release params

CI: adjust release params #21

Workflow file for this run

name: Sonoran CMS Core Release
on:
push:
branches:
- master
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Extract Version
id: extract-version
run: |
VERSION=$(grep -oP "version '\K\d+\.\d+\.\d+" sonorancms/fxmanifest.lua)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "Grabbed version number of $VERSION, will be used for this release..."
shell: bash
- name: Create Release Directory
id: create-release-dir
run: |
mkdir release
echo "Created release directory"
shell: bash
- name: Zip Directories
id: zip-dirs
run: |
VERSION=${{ steps.extract-version.outputs.version }}
mkdir [sonorancms]
mv sonorancms [sonorancms]/sonorancms
mv sonorancms_updatehelper [sonorancms]/sonorancms_updatehelper
zip -r "sonorancms_core-$VERSION.zip" [sonorancms]/
mv "sonorancms_core-$VERSION.zip" release/
echo "Zipped sonorancms/ and sonorancms_updatehelper/ directories"
shell: bash
- name: Create or Recreate Release
id: create-update-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=${{ steps.extract-version.outputs.version }}
RELEASE_NAME="v$VERSION"
RELEASE_TAG="$VERSION"
# Check if the release already exists
if curl --fail -sSL "https://api.github.com/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG"; then
echo "Deleting existing release $RELEASE_NAME"
RELEASE_ID=$(curl -X GET "https://api.github.com/repos/${{ github.repository }}/releases/tags/$RELEASE_TAG" \
-H "Authorization: token $GITHUB_TOKEN" | jq -r '.id')
curl -X DELETE "https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID" \
-H "Authorization: token $GITHUB_TOKEN"
fi
# Check if the tag exists, and if it does, delete it
if curl --fail -sSL "https://api.github.com/repos/${{ github.repository }}/git/refs/tags/$RELEASE_TAG"; then
echo "Deleting existing tag $RELEASE_TAG"
REF_SHA=$(curl -sSL "https://api.github.com/repos/${{ github.repository }}/git/refs/tags/$RELEASE_TAG" | jq -r '.object.sha')
curl -X DELETE "https://api.github.com/repos/${{ github.repository }}/git/refs/tags/$RELEASE_TAG" \
-H "Authorization: token $GITHUB_TOKEN"
else
echo "Tag $RELEASE_TAG does not exist"
fi
echo "Creating a new release $RELEASE_NAME"
RESPONSE=$(curl -X POST "https://api.github.com/repos/${{ github.repository }}/releases" \
-H "Authorization: token $GITHUB_TOKEN" \
-d "{\"tag_name\":\"$RELEASE_TAG\",\"name\":\"$RELEASE_NAME\",\"target_commitish\":\"master\",\"make_latest\":true,\"generate_release_notes\":true}")
RELEASE_ID=$(echo $RESPONSE | jq -r '.id')
# Upload the zip file as a release asset
echo "Uploading zip to release $RELEASE_NAME"
UPLOAD_URL="https://uploads.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?name=sonorancms_core-$VERSION.zip"
curl -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/zip" \
--data-binary "@release/sonorancms_core-$VERSION.zip" \
"$UPLOAD_URL"
shell: bash