mirror of
https://github.com/Melorise/cc-switch-nix-flake.git
synced 2026-11-07 14:49:32 +00:00
add auto update
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
name: Update upstream version
|
||||||
|
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "17 2 * * *"
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: update-upstream
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
update:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Check out repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Update version in flake.nix
|
||||||
|
id: update
|
||||||
|
env:
|
||||||
|
GH_TOKEN: ${{ github.token }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
latest_tag="$(curl --fail --silent --show-error --location \
|
||||||
|
-H 'Accept: application/vnd.github+json' \
|
||||||
|
-H "Authorization: Bearer $GH_TOKEN" \
|
||||||
|
https://api.github.com/repos/farion1231/cc-switch/releases/latest \
|
||||||
|
| jq --exit-status --raw-output '.tag_name')"
|
||||||
|
latest_version="${latest_tag#v}"
|
||||||
|
|
||||||
|
if [[ ! "$latest_tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
||||||
|
echo "Unsupported upstream release tag: $latest_tag" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
current_version="$(sed -nE \
|
||||||
|
's/^[[:space:]]*version = "([^"]+)";/\1/p' \
|
||||||
|
flake.nix | head -n 1)"
|
||||||
|
if [[ -z "$current_version" ]]; then
|
||||||
|
echo "Could not find the package version in flake.nix" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
newest_version="$(printf '%s\n' "$current_version" "$latest_version" | sort -V | tail -n 1)"
|
||||||
|
if [[ "$current_version" == "$latest_version" || "$newest_version" != "$latest_version" ]]; then
|
||||||
|
echo "No newer release available; current version is $current_version"
|
||||||
|
echo "updated=false" >> "$GITHUB_OUTPUT"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
current_pattern="${current_version//./\\.}"
|
||||||
|
sed -i -E "s/${current_pattern}/${latest_version}/g" flake.nix
|
||||||
|
|
||||||
|
echo "Updated CC Switch from $current_version to $latest_version"
|
||||||
|
echo "updated=true" >> "$GITHUB_OUTPUT"
|
||||||
|
echo "version=$latest_version" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Commit and push version update
|
||||||
|
if: steps.update.outputs.updated == 'true'
|
||||||
|
env:
|
||||||
|
VERSION: ${{ steps.update.outputs.version }}
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
git config user.name "github-actions[bot]"
|
||||||
|
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
||||||
|
git add flake.nix
|
||||||
|
git commit -m "chore: update cc-switch to $VERSION"
|
||||||
|
git push
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
cc-switch nix flake版
|
cc-switch nix flake版
|
||||||
官方nixpkgs更新太慢,appimage版又有输入错误,该版是从deb重打包的
|
官方nixpkgs更新太慢,appimage版又有输入错误,该版是从deb重打包的
|
||||||
|
|
||||||
|
GitHub Actions 每天北京时间 10:17(UTC 02:17)检查上游最新正式 Release。当上游版本高于当前版本时,工作流会替换 `flake.nix` 中的版本号(包括描述、下载链接和包版本),自动提交并推送。也可以通过 Actions 页面手动运行 `Update upstream version` 工作流。
|
||||||
|
|||||||
Reference in New Issue
Block a user