Skip to content

Update Sources

Update Sources #10

# Copyright 2024 RustFS Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Update Sources
on:
schedule:
- cron: '0 0 * * *' # Daily at midnight
workflow_dispatch: # Manual trigger
jobs:
update-sources:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
# Step 1: Disable automatic credential persistence
persist-credentials: false
- name: Install Nix
uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: Update sources.json
id: update_script
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
REPO="rustfs/rustfs"
LATEST_RELEASE=$(gh api repos/$REPO/releases --jq 'first')
VERSION=$(echo "$LATEST_RELEASE" | jq -r '.tag_name')
CURRENT_VERSION=$(jq -r '.version' sources.json)
if [ "$VERSION" == "$CURRENT_VERSION" ]; then
echo "Already up to date ($VERSION)"
echo "updated=false" >> $GITHUB_OUTPUT
exit 0
fi
echo "Updating to $VERSION..."
cat <<EOF > sources.json.new
{
"version": "$VERSION",
"downloadBase": "https://github.com/$REPO/releases/download",
"files": {
"x86_64-linux": { "name": "rustfs-linux-x86_64-musl-latest.zip" },
"aarch64-linux": { "name": "rustfs-linux-aarch64-musl-latest.zip" },
"x86_64-darwin": { "name": "rustfs-macos-x86_64-latest.zip" },
"aarch64-darwin": { "name": "rustfs-macos-aarch64-latest.zip" }
}
}
EOF
for system in "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"; do
FILE_NAME=$(jq -r --arg sys "$system" '.files[$sys].name' sources.json.new)
URL="https://github.com/$REPO/releases/download/$VERSION/$FILE_NAME"
echo "Fetching hash for $URL..."
HASH=$(nix-prefetch-url --type sha256 "$URL")
jq --arg sys "$system" --arg hash "$HASH" '.files[$sys].sha256 = $hash' sources.json.new > sources.json.tmp
mv sources.json.tmp sources.json.new
done
mv sources.json.new sources.json
echo "updated=true" >> $GITHUB_OUTPUT
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Clean up Git credentials
# Step 2: Explicitly remove any lingering Authorization headers in git config
run: git config --local --unset-all http.https://github.com/.extraheader || true
- name: Create Pull Request
if: steps.update_script.outputs.updated == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: update sources.json to ${{ steps.update_script.outputs.version }}"
committer: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
branch: "automation/update-sources-${{ steps.update_script.outputs.version }}"
delete-branch: true
title: "chore: update rustfs to ${{ steps.update_script.outputs.version }}"
body: |
## Description
Automated update of RustFS binaries to version `${{ steps.update_script.outputs.version }}`.
Verified SHA256 hashes for all platforms.
labels: |
dependencies
automated-pr