release #275
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
# This is a basic workflow to help you get started with Actions | |
name: release | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "00 23 * * *" | |
jobs: | |
build: | |
name: release | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Get last sing-box tags | |
id: getsb | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const sbLatestRelease = await github.rest.repos.getLatestRelease({ | |
owner: 'SagerNet', | |
repo: 'sing-box', | |
}); | |
core.setOutput("singbox_tag", sbLatestRelease.data.tag_name); | |
- name: prepare enviroment | |
run: | | |
sudo apt update | |
sudo apt install jq -y | |
- name: download resources | |
id: download | |
env: | |
IP_CONF_LINK: ${{ secrets.SB_IP_CFG }} | |
SITE_CONF_LINK: ${{ secrets.SB_SITE_CFG }} | |
run: | | |
wget -O 'geosite.db' 'https://github.com/simplerick-simplefun/sing-geosite/releases/latest/download/geosite.db' > /dev/null 2>&1 | |
wget -O 'geoip.db' 'https://github.com/simplerick-simplefun/sing-geoip/releases/latest/download/geoip.db' > /dev/null 2>&1 | |
if [ "${IP_CONF_LINK}" == '' ] || [ "${IP_CONF_LINK}" == 'null' ] || [ "${SITE_CONF_LINK}" == '' ] || [ "${SITE_CONF_LINK}" == 'null' ]; then | |
echo "ip_conf_file='./config/dest_ip_sets.json'" >> "$GITHUB_OUTPUT" | |
echo "site_conf_filee='./config/dest_site_sets.json'" >> "$GITHUB_OUTPUT" | |
else | |
echo "ip_conf_file=$(curl -s -J -O -w '%{filename_effective}' ${IP_CONF_LINK})" >> "$GITHUB_OUTPUT" | |
echo "site_conf_file=$(curl -s -J -O -w '%{filename_effective}' ${SITE_CONF_LINK})" >> "$GITHUB_OUTPUT" | |
fi | |
- name: build | |
id: build | |
run: | | |
echo "tag=$(date +'%Y%m%d%H%M')" >> "$GITHUB_OUTPUT" | |
ip_conf=${{ steps.download.outputs.ip_conf_file }} | |
site_conf=${{ steps.download.outputs.site_conf_file }} | |
bash build.sh "$ip_conf" "$site_conf" | |
- name: Upload artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release-build-artifacts | |
path: | | |
*.srs | |
- name: Push artifacts to release branch | |
if: steps.build.outcome == 'success' | |
run: | | |
mkdir dist | |
cp *.srs dist/ | |
git config --local user.email "${{ vars.OWNER_EMAIL }}" | |
git config --local user.name "github-action[bot]" | |
git fetch | |
git checkout release | |
git checkout --orphan release-orphan | |
git rm -rf . | |
cp dist/* . | |
git add *.srs | |
git commit -am "Updated at $(date)" | |
git branch -D release | |
git branch -m release | |
git remote add myrepo "https://${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" | |
git tag "${{ steps.build.outputs.tag }}" | |
git push myrepo "${{ steps.build.outputs.tag }}" | |
git push -f -u myrepo release | |
- name: Release | |
if: steps.build.outcome == 'success' | |
id: release | |
uses: softprops/[email protected] | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
draft: false | |
prerelease: false | |
append_body: false | |
fail_on_unmatched_files: true | |
name: "${{ steps.build.outputs.tag }}" | |
tag_name: "${{ steps.build.outputs.tag }}" | |
files: | | |
./*.srs | |
- name: Purge CDN Cache | |
if: steps.build.outcome == 'success' | |
env: | |
CF_ZONE_ID: ${{ secrets.CF_ZONE_ID }} | |
CF_ZONE_TOKEN: ${{ secrets.CF_ZONE_TOKEN }} | |
PURGE_URL: ${{ secrets.PURGE_URL }} | |
run: | | |
curl -L "https://purge.jsdelivr.net/gh/${{ github.repository }}@release/" > /dev/null 2>&1 | |
prefix="${PURGE_URL}" | |
files=$(find . -maxdepth 1 -type f -name "*.srs" -printf "\"${prefix}%f\", ") | |
file_urls=${files%, } # Remove the trailing comma and space | |
curl --request POST \ | |
--url "https://api.cloudflare.com/client/v4/zones/${CF_ZONE_ID}/purge_cache" \ | |
--header 'Content-Type: application/json' \ | |
--header "Authorization: Bearer ${CF_ZONE_TOKEN}" \ | |
--data "{\"files\": [${file_urls}]}" \ | |
> /dev/null 2>&1 | |