Sync Node ncrypto #3
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: Sync Node ncrypto | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| node_ref: | |
| description: Optional nodejs/node release tag to sync from | |
| required: false | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| - name: Sync from nodejs/node | |
| id: sync | |
| env: | |
| NODE_REF: ${{ inputs.node_ref }} | |
| run: | | |
| python3 tools/sync-node-ncrypto.py \ | |
| --node-ref "$NODE_REF" | |
| - name: Stop when there are no changes | |
| if: steps.sync.outputs.has_changes != 'true' | |
| run: echo 'No ncrypto changes to sync.' | |
| - name: Commit sync branch | |
| id: commit | |
| if: steps.sync.outputs.has_changes == 'true' | |
| run: | | |
| branch='${{ steps.sync.outputs.branch_name }}' | |
| git switch -c "$branch" | |
| if git ls-remote --exit-code --heads origin "$branch" >/dev/null; then | |
| git fetch origin "$branch:refs/remotes/origin/$branch" | |
| fi | |
| git config user.name 'github-actions[bot]' | |
| git config user.email '41898282+github-actions[bot]@users.noreply.github.com' | |
| git add \ | |
| .github/sync-node-ncrypto.json \ | |
| include/ncrypto.h \ | |
| src/engine.cpp \ | |
| src/ncrypto.cpp | |
| git commit \ | |
| -m 'chore: sync ncrypto from Node.js ${{ steps.sync.outputs.target_version }}' \ | |
| -m 'Node-Base-Commit: ${{ steps.sync.outputs.base_sha }}' \ | |
| -m 'Node-Target-Commit: ${{ steps.sync.outputs.target_sha }}' | |
| git push --force-with-lease origin "$branch" | |
| echo "branch=$branch" >> "$GITHUB_OUTPUT" | |
| - name: Prepare PR body | |
| if: steps.sync.outputs.has_changes == 'true' | |
| run: | | |
| { | |
| echo 'Syncs `deps/ncrypto` from Node.js `${{ steps.sync.outputs.target_version }}`.' | |
| echo | |
| echo '- Base node commit: `${{ steps.sync.outputs.base_sha }}`' | |
| echo '- Target node commit: `${{ steps.sync.outputs.target_sha }}`' | |
| if [ '${{ steps.sync.outputs.has_conflicts }}' = 'true' ]; then | |
| echo | |
| echo 'This PR was opened as a draft because the 3-way merge produced conflicts:' | |
| echo | |
| printf '%s\n' '${{ steps.sync.outputs.conflicts }}' | sed 's/^/- `/' | sed 's/$/`/' | |
| fi | |
| } > "$RUNNER_TEMP/pr-body.md" | |
| - name: Open or update PR | |
| if: steps.sync.outputs.has_changes == 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| branch='${{ steps.commit.outputs.branch }}' | |
| title='chore: sync ncrypto from Node.js ${{ steps.sync.outputs.target_version }}' | |
| existing_url="$(gh pr list --state open --head "$branch" --json url --jq '.[0].url // ""')" | |
| if [ -n "$existing_url" ]; then | |
| gh pr edit "$existing_url" --title "$title" --body-file "$RUNNER_TEMP/pr-body.md" | |
| if [ '${{ steps.sync.outputs.has_conflicts }}' = 'true' ]; then | |
| gh pr ready "$existing_url" --undo || true | |
| else | |
| gh pr ready "$existing_url" || true | |
| fi | |
| echo "$existing_url" | |
| exit 0 | |
| fi | |
| args=( | |
| pr create | |
| --base main | |
| --head "$branch" | |
| --title "$title" | |
| --body-file "$RUNNER_TEMP/pr-body.md" | |
| ) | |
| if [ '${{ steps.sync.outputs.has_conflicts }}' = 'true' ]; then | |
| args+=(--draft) | |
| fi | |
| gh "${args[@]}" |