|
| 1 | +name: Sync Node ncrypto |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + node_ref: |
| 7 | + description: nodejs/node ref to sync from |
| 8 | + required: true |
| 9 | + default: main |
| 10 | + base_node_ref: |
| 11 | + description: Optional previous nodejs/node ref for bootstrap or recovery |
| 12 | + required: false |
| 13 | + default: '' |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + |
| 19 | +jobs: |
| 20 | + sync: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 24 | + with: |
| 25 | + ref: main |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Sync from nodejs/node |
| 29 | + id: sync |
| 30 | + env: |
| 31 | + NODE_REF: ${{ inputs.node_ref }} |
| 32 | + BASE_NODE_REF: ${{ inputs.base_node_ref }} |
| 33 | + run: | |
| 34 | + python3 tools/sync-node-ncrypto.py \ |
| 35 | + --node-ref "$NODE_REF" \ |
| 36 | + --base-node-ref "$BASE_NODE_REF" |
| 37 | +
|
| 38 | + - name: Stop when there are no changes |
| 39 | + if: steps.sync.outputs.has_changes != 'true' |
| 40 | + run: echo 'No ncrypto changes to sync.' |
| 41 | + |
| 42 | + - name: Commit sync branch |
| 43 | + id: commit |
| 44 | + if: steps.sync.outputs.has_changes == 'true' |
| 45 | + run: | |
| 46 | + branch='${{ steps.sync.outputs.branch_name }}' |
| 47 | + git switch -c "$branch" |
| 48 | + git fetch origin "$branch:refs/remotes/origin/$branch" || true |
| 49 | + git config user.name 'github-actions[bot]' |
| 50 | + git config user.email '41898282+github-actions[bot]@users.noreply.github.com' |
| 51 | + git add \ |
| 52 | + .github/sync-node-ncrypto.json \ |
| 53 | + include/ncrypto.h \ |
| 54 | + src/engine.cpp \ |
| 55 | + src/ncrypto.cpp |
| 56 | + git commit \ |
| 57 | + -m 'chore: sync ncrypto from nodejs/node' \ |
| 58 | + -m 'Node-Base-Commit: ${{ steps.sync.outputs.base_sha }}' \ |
| 59 | + -m 'Node-Target-Commit: ${{ steps.sync.outputs.target_sha }}' |
| 60 | + git push --force-with-lease origin "$branch" |
| 61 | + echo "branch=$branch" >> "$GITHUB_OUTPUT" |
| 62 | +
|
| 63 | + - name: Prepare PR body |
| 64 | + if: steps.sync.outputs.has_changes == 'true' |
| 65 | + run: | |
| 66 | + { |
| 67 | + echo 'Syncs `deps/ncrypto` from `nodejs/node` into this repository.' |
| 68 | + echo |
| 69 | + echo '- Base node commit: `${{ steps.sync.outputs.base_sha }}`' |
| 70 | + echo '- Target node commit: `${{ steps.sync.outputs.target_sha }}`' |
| 71 | + echo '- Conflicts: `${{ steps.sync.outputs.has_conflicts }}`' |
| 72 | + if [ '${{ steps.sync.outputs.has_conflicts }}' = 'true' ]; then |
| 73 | + echo |
| 74 | + echo 'This PR was opened as a draft because the 3-way merge produced conflicts:' |
| 75 | + echo |
| 76 | + printf '%s\n' '${{ steps.sync.outputs.conflicts }}' | sed 's/^/- `/' | sed 's/$/`/' |
| 77 | + fi |
| 78 | + } > "$RUNNER_TEMP/pr-body.md" |
| 79 | +
|
| 80 | + - name: Open or update PR |
| 81 | + if: steps.sync.outputs.has_changes == 'true' |
| 82 | + env: |
| 83 | + GH_TOKEN: ${{ github.token }} |
| 84 | + run: | |
| 85 | + branch='${{ steps.commit.outputs.branch }}' |
| 86 | + title='chore: sync ncrypto from nodejs/node' |
| 87 | + existing_url="$(gh pr view "$branch" --json url --jq .url 2>/dev/null || true)" |
| 88 | + if [ -n "$existing_url" ]; then |
| 89 | + gh pr edit "$branch" --title "$title" --body-file "$RUNNER_TEMP/pr-body.md" |
| 90 | + if [ '${{ steps.sync.outputs.has_conflicts }}' = 'true' ]; then |
| 91 | + gh pr ready "$branch" --undo || true |
| 92 | + else |
| 93 | + gh pr ready "$branch" || true |
| 94 | + fi |
| 95 | + echo "$existing_url" |
| 96 | + exit 0 |
| 97 | + fi |
| 98 | +
|
| 99 | + args=( |
| 100 | + pr create |
| 101 | + --base main |
| 102 | + --head "$branch" |
| 103 | + --title "$title" |
| 104 | + --body-file "$RUNNER_TEMP/pr-body.md" |
| 105 | + ) |
| 106 | + if [ '${{ steps.sync.outputs.has_conflicts }}' = 'true' ]; then |
| 107 | + args+=(--draft) |
| 108 | + fi |
| 109 | + gh "${args[@]}" |
0 commit comments