Merge pull request #42 from Jordan2139/master #42
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: Sonoran CMS Core Release | |
on: | |
push: | |
branches: | |
- master | |
jobs: | |
release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v2 | |
- name: Set Auth Token | |
run: | | |
if [ -z "${{ secrets.PAT_OVERRIDE }}" ]; then | |
echo "AUTH_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV | |
else | |
echo "AUTH_TOKEN=${{ secrets.PAT_OVERRIDE }}" >> $GITHUB_ENV | |
fi | |
shell: bash | |
- 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 | |
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 $AUTH_TOKEN" | jq -r '.id') | |
curl -X DELETE "https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID" \ | |
-H "Authorization: token $AUTH_TOKEN" | |
else | |
echo "Release $RELEASE_NAME does not exist" | |
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 $AUTH_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 $AUTH_TOKEN" \ | |
-d "{\"tag_name\":\"$RELEASE_TAG\",\"name\":\"$RELEASE_NAME\",\"target_commitish\":\"master\",\"draft\":false,\"prerelease\":false,\"generate_release_notes\":true,\"make_latest\":\"true\"}") | |
echo $RESPONSE | |
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 $AUTH_TOKEN" \ | |
-H "Content-Type: application/zip" \ | |
--data-binary "@release/sonorancms_core-$VERSION.zip" \ | |
"$UPLOAD_URL" | |
shell: bash |