Check and Update Tailscale Binary #155
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: Check and Update Tailscale Binary | |
on: | |
schedule: | |
- cron: '0 0 * * *' # Runs every day at midnight | |
workflow_dispatch: | |
inputs: | |
force: | |
type: boolean | |
description: 'Force update' | |
required: false | |
default: false | |
permissions: | |
contents: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get latest release from tailscale | |
id: get_latest_release | |
uses: octokit/[email protected] | |
with: | |
route: GET /repos/tailscale/tailscale/releases/latest | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Check current version is up to date | |
id: check_version | |
run: | | |
NEW_TAG="${{ fromJSON(steps.get_latest_release.outputs.data).tag_name }}" | |
VERSION="${{ fromJSON(steps.get_latest_release.outputs.data).name }}" | |
CURRENT_TAG=$(curl -s https://raw.githubusercontent.com/anasfanani/Magisk-Tailscaled/master/files/VERSION.txt) | |
if [[ "$NEW_TAG" == "$CURRENT_TAG" && "${{ github.event.inputs.force }}" != 'true' ]]; then | |
echo "Current version is up to date" | |
echo "exit=true" >> $GITHUB_OUTPUT | |
else | |
echo "Current version is $CURRENT_TAG, latest version is $NEW_TAG" | |
echo "Updating to latest version" | |
echo "exit=false" >> $GITHUB_OUTPUT | |
echo "version=$VERSION" >> $GITHUB_OUTPUT | |
echo "new_tag=$NEW_TAG" >> $GITHUB_OUTPUT | |
echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT | |
fi | |
shell: bash | |
- name: Checkout code | |
if: steps.check_version.outputs.exit != 'true' | |
uses: actions/checkout@v3 | |
- name: Download and unzip latest tailscale binaries | |
if: steps.check_version.outputs.exit != 'true' | |
run: | | |
PREFIX=${{ steps.check_version.outputs.version }} | |
PREFIX=${PREFIX#v} | |
ARCHS=("arm" "arm64") | |
mkdir -p files | |
cd files | |
for ARCH in ${ARCHS[@]}; do | |
URL="https://pkgs.tailscale.com/stable/tailscale_${PREFIX}_${ARCH}.tgz" | |
curl -LO $URL | |
tar -xzf "tailscale_${PREFIX}_${ARCH}.tgz" "tailscale_${PREFIX}_${ARCH}/tailscaled" "tailscale_${PREFIX}_${ARCH}/tailscale" | |
mv "tailscale_${PREFIX}_${ARCH}/tailscaled" "tailscaled-${ARCH}" | |
mv "tailscale_${PREFIX}_${ARCH}/tailscale" "tailscale-${ARCH}" | |
rm -r "tailscale_${PREFIX}_${ARCH}" | |
rm "tailscale_${PREFIX}_${ARCH}.tgz" | |
done | |
cd .. | |
ls -la files | |
- name: Update VERSION.txt | |
if: steps.check_version.outputs.exit != 'true' | |
run: | | |
echo ${{ steps.check_version.outputs.new_tag }} > files/VERSION.txt | |
- name: Update update.json and module.prop | |
if: steps.check_version.outputs.exit != 'true' | |
run: | | |
versionString="${{ steps.check_version.outputs.version }}.0" | |
versionString=${versionString//[^0-9.]/} | |
new_tag="${{ steps.check_version.outputs.new_tag }}.0" | |
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 | |
if: steps.check_version.outputs.exit != 'true' | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action" | |
VERSION=${{ steps.check_version.outputs.version }} | |
ARCHS=("arm" "arm64") | |
for ARCH in ${ARCHS[@]}; do | |
if [[ -f files/tailscaled-${ARCH} && -f files/tailscale-${ARCH} ]]; then | |
git add files/tailscaled-${ARCH} files/tailscale-${ARCH} | |
if git diff --staged --quiet; then | |
echo "No changes to commit update ${{ steps.check_version.outputs.current_tag }}" | |
else | |
git commit -m "Updated from ${{ steps.check_version.outputs.current_tag }} to ${{ steps.check_version.outputs.new_tag }} for $ARCH" | |
fi | |
else | |
echo "Files for architecture $ARCH do not exist" | |
exit 1; | |
fi | |
done | |
git add . | |
if git diff --staged --quiet; then | |
echo "No changes to commit" | |
else | |
git commit -m "Updated version from ${{ steps.check_version.outputs.current_tag }} to ${{ steps.check_version.outputs.new_tag }}" | |
git tag ${{ steps.check_version.outputs.new_tag }}.0 | |
git push origin ${{ steps.check_version.outputs.new_tag }}.0 | |
git push | |
fi | |
- name: Create zip file | |
if: steps.check_version.outputs.exit != 'true' | |
run: | | |
# zip all files | |
zip -9 -r "Magisk-Tailscaled-${{ steps.check_version.outputs.new_tag }}.0.zip" . -x "*.git*" | |
# doing job for arm64 | |
sed -i 's/arm) F_ARCH=$ARCH;;/#arm) F_ARCH=$ARCH;;/g' customize.sh # disable arm | |
zip -9 -r "Magisk-Tailscaled-arm64-${{ steps.check_version.outputs.new_tag }}.0.zip" . -x "*.git*" "files/tailscale-arm" "files/tailscaled-arm" "files/hev-socks5-tunnel-linux-arm" "*.zip" | |
# doing job for arm | |
sed -i 's/#arm) F_ARCH=$ARCH;;/arm) F_ARCH=$ARCH;;/g' customize.sh # enable arm | |
sed -i 's/arm64) F_ARCH=$ARCH;;/#arm64) F_ARCH=$ARCH;;/g' customize.sh # disable arm64 | |
zip -9 -r "Magisk-Tailscaled-arm-${{ steps.check_version.outputs.new_tag }}.0.zip" . -x "*.git*" "files/tailscale-arm64" "files/tailscaled-arm64" "files/hev-socks5-tunnel-linux-arm64" "*.zip" | |
- name: Create Release | |
if: steps.check_version.outputs.exit != 'true' | |
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.new_tag }}.0.zip | |
Magisk-Tailscaled-arm64-${{ steps.check_version.outputs.new_tag }}.0.zip | |
Magisk-Tailscaled-arm-${{ steps.check_version.outputs.new_tag }}.0.zip | |
name: Magisk Tailscaled ${{ steps.check_version.outputs.new_tag }}.0 | |
tag_name: ${{ steps.check_version.outputs.new_tag }}.0 | |
- name: Show output | |
run: | | |
echo "URL: ${{ steps.create_release.outputs.url }}" | |
echo "ID: ${{ steps.create_release.outputs.id }}" | |
echo "Upload URL: ${{ steps.create_release.outputs.upload_url }}" | |
echo "Assets: ${{ steps.create_release.outputs.assets }}" | |