Skip to content

Commit

Permalink
chore(ci): fix sync.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Jan 13, 2025
1 parent 256cf8a commit 5c73727
Showing 1 changed file with 88 additions and 9 deletions.
97 changes: 88 additions & 9 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@ on:
# Run once a week at 00:05 UTC on Friday.
- cron: 5 0 * * 5

permissions:
contents: read

jobs:
fetch-latest-versions:
runs-on: ubuntu-latest
permissions:
contents: write
runs-on: ubuntu-latest
pull-requests: write
env:
HEAD_BRANCH: actions/tools-update-config.json

steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: Install Node
uses: actions/setup-node@v4
Expand Down Expand Up @@ -46,13 +54,84 @@ jobs:
},
}" > config.json
- uses: gr2m/create-or-update-pull-request-action@77596e3166f328b24613f7082ab30bf2d93079d5 # v1.9.2
# Creates a PR or update the Action's existing PR, or
# no-op if the base branch is already up-to-date.
- name: Check if there have been changes
id: check-for-changes
run: |
if git fetch origin "$HEAD_BRANCH"; then
git diff --exit-code --quiet FETCH_HEAD config.json || echo "CONTAINS_CHANGES=true" >> "$GITHUB_OUTPUT"
else
git diff --exit-code --quiet HEAD config.json || echo "CONTAINS_CHANGES=true" >> "$GITHUB_OUTPUT"
fi
- run: corepack yarn install --immutable
if: steps.check-for-changes.outputs.CONTAINS_CHANGES == 'true'
- run: corepack yarn build # We need the stubs to run the tests
if: steps.check-for-changes.outputs.CONTAINS_CHANGES == 'true'

- name: Remove old Nock files to avoid conflicts
if: steps.check-for-changes.outputs.CONTAINS_CHANGES == 'true'
run: rm tests/nocks.db

- run: corepack yarn test
if: steps.check-for-changes.outputs.CONTAINS_CHANGES == 'true'
env:
NOCK_ENV: record

- name: Push changes
if: steps.check-for-changes.outputs.CONTAINS_CHANGES == 'true'
run: |
HEAD_SHA=
if git fetch origin "$HEAD_BRANCH"; then
HEAD_SHA="$(git rev-parse FETCH_HEAD)"
else
# The branch does not exist yet, creating it.
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${GITHUB_REPOSITORY}/git/refs" \
-f "ref=refs/heads/$HEAD_BRANCH" -f "sha=$GITHUB_SHA"
fi
gh api graphql \
-F repo="$GITHUB_REPOSITORY" -F branch='actions/tools-update-config.json' \
-F parentCommitSha="${HEAD_SHA:-$GITHUB_SHA}" \
-F commit_title="$COMMIT_MESSAGE" \
-F changes="$(node -p 'JSON.stringify({
additions: ["config.json", "tests/nocks.db"].map(path => ({ path, contents: fs.readFileSync(path).toString("base64") })),
deletions: [],
})')"
-f query='mutation ($repo: String! $branch: String!, $parentCommitSha: GitObjectID!, $changes: FileChanges!, $commit_title: String!, $commit_body: String) {
createCommitOnBranch(input: {
branch: {
repositoryNameWithOwner: $repo,
branchName: $branch
},
message: {
headline: $commit_title,
body: $commit_body
},
expectedHeadOid: $parentCommitSha,
fileChanges: $changes
}) {
commit {
url
}
}
}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
body: This is an automated update of package manager versions
branch: actions/tools-update-config.json
commit-message: "feat: update package manager versions"
title: "feat: update package manager versions"
COMMIT_MESSAGE: "feat: update package manager versions"

- name: Create PR if it does not exist
if: steps.check-for-changes.outputs.CONTAINS_CHANGES == 'true'
run: |
gh api \
--method POST \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"/repos/${GITHUB_REPOSITORY}/pulls" \
-f "title=$TITLE" -f "body=$BODY" -f "head=$HEAD_BRANCH"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BODY: This is an automated update of package manager versions
TITLE: "feat: update package manager versions"

0 comments on commit 5c73727

Please sign in to comment.