diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e1edd8f --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,87 @@ +name: Sonoran CAD Framework 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+" sonorancad/fxmanifest.lua) + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "Grabbed version number of $VERSION, will be used for this release..." + shell: bash + + - name: Clone included submodules + id: clone-submodules + run: | + git clone https://github.com/Sonoran-Software/wk_wars2x.git wk_wars2x + git clone https://github.com/Sonoran-Software/id_card_ui.git sonoran_idcard + shell: bash + + - name: Cleanup & Zip Directories + id: zip-dirs + run: | + VERSION=${{ steps.extract-version.outputs.version }} + find sonorancad/plugins -mindepth 1 -type d -exec sh -c 'case "$0" in */readme.md|*/template) ;; *) rm -r "$0" ;; esac' {} \; & wait + rsync -a --exclude="[sonorancad]" --exclude=".git" --exclude=".vscode" --exclude=".github" ./ ./[sonorancad] + zip -r "sonorancad-$VERSION.zip" [sonorancad]/ + echo "Zipped sonorancad/ and sonorancad_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="Release $VERSION" + RELEASE_TAG="v$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" + 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 $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\",\"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=sonorancad-$VERSION.zip" + curl -H "Authorization: token $GITHUB_TOKEN" \ + -H "Content-Type: application/zip" \ + --data-binary "@sonorancad-$VERSION.zip" \ + "$UPLOAD_URL" + shell: bash \ No newline at end of file diff --git a/sonorancad/tools/README.md b/sonorancad/tools/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/sonorancad/tools/build.ps1 b/sonorancad/tools/build.ps1 deleted file mode 100644 index e537567..0000000 --- a/sonorancad/tools/build.ps1 +++ /dev/null @@ -1,27 +0,0 @@ -# Pointless for end-users, supplied in case someone else needs to build a release. - -# Place into folder above your [sonorancad] before running. Requires 7-zip to be installed. - -$ReleaseVersion = Read-Host "Enter version to create" - -$ResourcePath = "G:\git\sonoranplugins\server\resources\[sonorancad]" -$WorkPath = $PSScriptRoot + "\release\[sonorancad]" - -Write-Host $ResourcePath -Write-Host $WorkPath - -Robocopy.exe $ResourcePath $WorkPath /s /MIR /XD plugins .git .vscode /XF config.json config_*.lua .gitignore config.js config.lua *.ydr *.ytyp -New-Item -ItemType Directory "$WorkPath\sonorancad\plugins" -ErrorAction Ignore -Robocopy.exe "$ResourcePath\sonorancad\plugins\template" "$WorkPath\sonorancad\plugins\template" /s - -Remove-Item "$PSScriptRoot\sonorancad-$ReleaseVersion.zip" - -$7zipPath = "$env:ProgramFiles\7-Zip\7z.exe" - -if (-not (Test-Path -Path $7zipPath -PathType Leaf)) { - throw "7 zip file '$7zipPath' not found" -} - -Set-Alias 7zip $7zipPath - -7zip a -mx=9 "$PSScriptRoot\sonorancad-$ReleaseVersion.zip" $WorkPath \ No newline at end of file