Update Release #20
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: Update Release | |
on: | |
workflow_dispatch: | |
inputs: | |
increment: | |
description: 'Increment version' | |
required: false | |
default: 'false' | |
permissions: | |
contents: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Check current version | |
id: check_version | |
run: | | |
VERSION=$(cat update.json | jq -r '.version') | |
VERSION_CODE=$(cat update.json | jq -r '.versionCode') | |
if [[ "${{ github.event.inputs.increment }}" == 'true' ]]; then | |
echo "Incrementing version" | |
echo "old_version=$VERSION" >> $GITHUB_OUTPUT | |
echo "old_version_code=$VERSION_CODE" >> $GITHUB_OUTPUT | |
VERSION_CODE=$(printf "%08d" $((10#${VERSION_CODE}+1))) | |
VERSION=$(echo $VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g') | |
echo New version code: $VERSION_CODE | |
echo New version: $VERSION | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
echo "version_code=$VERSION_CODE" >> $GITHUB_OUTPUT | |
else | |
echo Version code: $VERSION_CODE | |
echo Version: $VERSION | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
echo "version_code=$VERSION_CODE" >> $GITHUB_OUTPUT | |
fi | |
shell: bash | |
- name: Update update.json and module.prop | |
run: | | |
versionString="$(echo ${{ steps.check_version.outputs.version }}| tr -dc '0-9.')" | |
new_tag="${{ steps.check_version.outputs.version }}" | |
zipUrl="https://github.com/anasfanani/Magisk-Tailscaled/releases/download/$new_tag/Magisk-Tailscaled-$new_tag.zip" | |
IFS='.' read -ra VERSION_PARTS <<< "$versionString" | |
newVersionCode=$(printf "%02d%02d%02d%02d" "${VERSION_PARTS[0]}" "${VERSION_PARTS[1]}" "${VERSION_PARTS[2]}" "${VERSION_PARTS[3]}") | |
jq '.version = $newVersion | .versionCode = $newVersionCode | .zipUrl = $newZipUrl | .changelog = $newChangelog' \ | |
--arg newVersion "$new_tag" \ | |
--arg newVersionCode "$newVersionCode" \ | |
--arg newZipUrl "$zipUrl" \ | |
--arg newChangelog "https://raw.githubusercontent.com/anasfanani/Magisk-Tailscaled/master/CHANGELOG.txt" \ | |
update.json > temp.json && mv temp.json update.json | |
sed -i "s/^version=.*/version=$versionString/" module.prop | |
sed -i "s/^versionCode=.*/versionCode=$newVersionCode/" module.prop | |
- name: Commit and push | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
VERSION="$(echo ${{ steps.check_version.outputs.version }}| tr -dc '0-9.')" | |
git add . | |
if git diff --staged --quiet; then | |
echo "No changes to commit" | |
else | |
if git ls-remote --tags origin | grep ${{ steps.check_version.outputs.version }}; then | |
echo "Tag already exists. Force delete." | |
git push origin :refs/tags/${{ steps.check_version.outputs.version }} | |
fi | |
if [[ "${{ github.event.inputs.increment }}" == 'true' ]]; then | |
git commit -m "Updated version from ${{ steps.check_version.outputs.old_version }} to ${{ steps.check_version.outputs.version }}" | |
git tag ${{ steps.check_version.outputs.version }} | |
else | |
git commit -m "Updated version to ${{ steps.check_version.outputs.version }}" | |
fi | |
git push origin ${{ steps.check_version.outputs.version }} | |
git push | |
fi | |
- name: Create zip file | |
run: | | |
zip -r "Magisk-Tailscaled-${{ steps.check_version.outputs.version }}.zip" . -x "*.git*" | |
- name: Create Release | |
id: create_release | |
uses: softprops/action-gh-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
generate_release_notes: true | |
files: ./Magisk-Tailscaled-${{ steps.check_version.outputs.version }}.zip | |
name: Magisk Tailscaled ${{ steps.check_version.outputs.version }} | |
tag_name: ${{ steps.check_version.outputs.version }} | |