This commit is contained in:
m3tm3re
2026-01-18 07:17:32 +01:00
parent cc9e70d6d6
commit 109cfbd515

View File

@@ -16,42 +16,39 @@ env:
GIT_COMMITTER_NAME: "nix-update bot" GIT_COMMITTER_NAME: "nix-update bot"
GIT_COMMITTER_EMAIL: "bot@m3ta.dev" GIT_COMMITTER_EMAIL: "bot@m3ta.dev"
GIT_TERMINAL_PROMPT: "0" GIT_TERMINAL_PROMPT: "0"
GIT_ASKPASS: "/bin/echo"
jobs: jobs:
nix-update: nix-update:
runs-on: nixos runs-on: nixos
steps: steps:
- name: Configure Authentication (.netrc)
run: |
# Configure .netrc for seamless authentication
# This bypasses git credential helpers and works reliably in CI environments
cat <<NETRC > $HOME/.netrc
machine code.m3ta.dev
login m3tam3re
password ${{ secrets.NIX_UPDATE_TOKEN }}
NETRC
chmod 600 $HOME/.netrc
- name: Checkout repository - name: Checkout repository
run: | run: |
# Clean up any previous runs
if [ -d "/tmp/nixpkgs" ]; then if [ -d "/tmp/nixpkgs" ]; then
rm -rf /tmp/nixpkgs rm -rf /tmp/nixpkgs
fi fi
# 1. Configure Credentials Globally using a Credential Helper Script # Clone using the HTTPS URL (auth handled by .netrc)
# This is the most robust way to handle auth without leaking tokens in `ps` output
# and ensuring it works for all git commands (clone, push, submodules)
# Create a dummy askpass script that returns the password (token)
echo 'echo "${{ secrets.NIX_UPDATE_TOKEN }}"' > /tmp/git-askpass-helper.sh
chmod +x /tmp/git-askpass-helper.sh
export GIT_ASKPASS="/tmp/git-askpass-helper.sh"
# Clone using the username 'm3tam3re' explicitly.
# Gitea PATs usually require the username to match the token owner for write operations.
git clone --no-single-branch \ git clone --no-single-branch \
"https://m3tam3re@code.m3ta.dev/m3tam3re/nixpkgs.git" \ "https://code.m3ta.dev/m3tam3re/nixpkgs.git" \
/tmp/nixpkgs /tmp/nixpkgs
cd /tmp/nixpkgs cd /tmp/nixpkgs
# Configure local git user
git config user.name "${{ env.GIT_AUTHOR_NAME }}" git config user.name "${{ env.GIT_AUTHOR_NAME }}"
git config user.email "${{ env.GIT_AUTHOR_EMAIL }}" git config user.email "${{ env.GIT_AUTHOR_EMAIL }}"
git config init.defaultBranch master git config init.defaultBranch master
# Verify checkout
git status git status
git log --oneline -5 git log --oneline -5
@@ -66,7 +63,6 @@ jobs:
exit 1 exit 1
fi fi
# Check if flake.nix exists
if [ -f "flake.nix" ]; then if [ -f "flake.nix" ]; then
echo "has_flake=true" >> $GITHUB_OUTPUT echo "has_flake=true" >> $GITHUB_OUTPUT
else else
@@ -171,10 +167,8 @@ jobs:
BRANCH="${{ steps.update.outputs.branch_name }}" BRANCH="${{ steps.update.outputs.branch_name }}"
PACKAGES="${{ steps.update.outputs.updated_packages }}" PACKAGES="${{ steps.update.outputs.updated_packages }}"
# Re-export the helper for this step just in case
export GIT_ASKPASS="/tmp/git-askpass-helper.sh"
echo "Pushing branch ${BRANCH}..." echo "Pushing branch ${BRANCH}..."
# Authentication is handled by .netrc
git push origin "${BRANCH}" git push origin "${BRANCH}"
echo "Creating pull request..." echo "Creating pull request..."
@@ -184,7 +178,6 @@ jobs:
exit 1 exit 1
fi fi
# Reset tea login
tea login delete m3ta >/dev/null 2>&1 || true tea login delete m3ta >/dev/null 2>&1 || true
tea login add --name m3ta --url https://code.m3ta.dev --token "${{ secrets.NIX_UPDATE_TOKEN }}" tea login add --name m3ta --url https://code.m3ta.dev --token "${{ secrets.NIX_UPDATE_TOKEN }}"
@@ -197,9 +190,9 @@ jobs:
--body "$(printf "Automated package updates using nix-update.\n\nUpdated packages:\n%s\n\nCommits:\n%s" "$PACKAGES" "$COMMITS")" \ --body "$(printf "Automated package updates using nix-update.\n\nUpdated packages:\n%s\n\nCommits:\n%s" "$PACKAGES" "$COMMITS")" \
--assignees m3tam3re \ --assignees m3tam3re \
--labels automated-update || echo "PR creation failed" --labels automated-update || echo "PR creation failed"
# Cleanup # Cleanup
rm -f /tmp/git-askpass-helper.sh rm -f $HOME/.netrc
- name: Summary - name: Summary
if: always() if: always()