更新 update_hosts.yml #6
Workflow file for this run
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 hosts | |
on: | |
push: | |
schedule: | |
- cron: '0 */4 * * *' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
update-hosts: | |
runs-on: ubuntu-latest | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
cache: 'pip' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
sudo pip install -r requirements.txt | |
echo "Installed packages:" | |
sudo pip list | |
- name: Run hosts update script | |
run: | | |
echo "Python version and location:" | |
python -V | |
which python | |
echo "Running script with sudo..." | |
sudo python SetHosts.py --verbose | |
- name: Commit and push changes | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "action_bot" | |
if [[ -n $(git status -s) ]]; then | |
git add . | |
git commit -m "chore: update hosts content [skip ci]" | |
git push "https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" | |
else | |
echo "No changes to commit" | |
fi |