Created
November 9, 2024 16:34
-
-
Save schickling/1481d81ec95c3b61c74d79450ae6655e to your computer and use it in GitHub Desktop.
GitHub action fix pnpm lock file
This file contains hidden or 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: Fix Lock File and Create PR | |
on: | |
push: | |
branches: | |
- '**' # Run on every branch push | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
fix-lockfile: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- uses: cachix/install-nix-action@v25 | |
- uses: DeterminateSystems/magic-nix-cache-action@v2 | |
- name: Create new branch | |
run: | | |
git config --global user.name 'github-actions[bot]' | |
git config --global user.email 'github-actions[bot]@users.noreply.github.com' | |
# Extract branch name from the full reference path | |
REF_BRANCH_NAME=$(echo "${{ github.ref }}" | sed 's|refs/heads/||') | |
echo "REF_BRANCH_NAME=${REF_BRANCH_NAME}" >> $GITHUB_ENV | |
BRANCH_NAME="fix-lockfile-${REF_BRANCH_NAME}" | |
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV | |
git checkout -b $BRANCH_NAME | |
- run: nix develop --command pnpm install --fix-lockfile --no-frozen-lockfile | |
- name: Check for changes | |
id: check_changes | |
run: | | |
git status | |
git add pnpm-lock.yaml | |
if [ -n "$(git diff --cached --name-only)" ]; then | |
echo 'HAS_CHANGES=true' >> $GITHUB_ENV | |
else | |
echo 'HAS_CHANGES=false' >> $GITHUB_ENV | |
fi | |
- name: Commit changes | |
if: ${{ env.HAS_CHANGES == 'true' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git commit -m "fix: update pnpm lockfile with pnpm install --fix-lockfile" | |
git push --force --set-upstream origin $BRANCH_NAME | |
- name: Create PR | |
if: ${{ env.HAS_CHANGES == 'true' }} | |
uses: devops-infra/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
source_branch: ${{ env.BRANCH_NAME }} | |
target_branch: ${{ env.REF_BRANCH_NAME }} | |
title: "Fix: Update PNPM Lockfile" | |
body: "**Automated pull request**" | |
label: dependencies | |
draft: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment