Skip to content

Commit 1d2696d

Browse files
authored
add "update remote files" workflow to plugindemo as well
for now, runs every day. But once N++ repo has the "release-notifier" workflow added, then the schedule can be turned off here. (This destination workflow needs to be in place _before_ "release-notifier" starts running upstream.)
1 parent 976a172 commit 1d2696d

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: CI_update_remote
2+
3+
on:
4+
# on demand, from Actions tab
5+
workflow_dispatch:
6+
7+
# on schedule (using cron syntax)
8+
schedule:
9+
- cron: "0 0 * * *" #< every day at 00:00 UTC
10+
11+
jobs:
12+
update:
13+
# This job would annoy people who fork the template, or if plugintemplate ever becomes a "template repository"
14+
# if someone _wants_ this, change the name to match their own fork or project
15+
if: ${{ github.repository == 'npp-plugins/plugindemo' }}
16+
17+
permissions:
18+
contents: write
19+
20+
runs-on: windows-latest
21+
22+
steps:
23+
- name: Checkout plugintemplate repo
24+
uses: actions/checkout@v4
25+
26+
- name: Checkout N++ repo
27+
uses: actions/checkout@v4
28+
with:
29+
repository: notepad-plus-plus/notepad-plus-plus
30+
path: npp_repo
31+
filter: 'blob:none'
32+
33+
- name: Diff the hashes
34+
id: diff_step
35+
run: |
36+
# start assuming no differences
37+
$anyDifference = $false
38+
#
39+
#### Always trigger build on workflow_dispatch
40+
#
41+
if("${{ github.event_name }}" -eq "workflow_dispatch") {
42+
$anyDifference = $true
43+
}
44+
#
45+
# Define the local_path => upstream_path pairs
46+
#
47+
$pairs = @{
48+
"src\\Scintilla.h" = "npp_repo\\scintilla\\include\\Scintilla.h"
49+
"src\\Sci_Position.h" = "npp_repo\\scintilla\\include\\Sci_Position.h"
50+
"src\\Notepad_plus_msgs.h" = "npp_repo\\PowerEditor\\src\\MISC\\PluginsManager\\Notepad_plus_msgs.h"
51+
"src\\PluginInterface.h" = "npp_repo\\PowerEditor\\src\\MISC\\PluginsManager\\PluginInterface.h"
52+
"src\\menuCmdID.h" = "npp_repo\\PowerEditor\\src\\menuCmdID.h"
53+
"src\\DockingFeature\\Docking.h" = "npp_repo\\PowerEditor\\src\\WinControls\\DockingWnd\\Docking.h"
54+
"src\\DockingFeature\\dockingResource.h" = "npp_repo\\PowerEditor\\src\\WinControls\\DockingWnd\\dockingResource.h"
55+
##
56+
### The following might be useful to plugin developers, but may require changes to make them compatible
57+
### as such, they are listed for reference, but not included as part of the automatic update
58+
### of the template
59+
##
60+
#"src\\DockingFeature\\DockingDlgInterface.h" = "npp_repo\\PowerEditor\\src\\WinControls\\DockingWnd\\DockingDlgInterface.h"
61+
#"src\\DockingFeature\\StaticDialog.h" = "npp_repo\\PowerEditor\\src\\WinControls\\StaticDialog\\StaticDialog.h"
62+
#"src\\DockingFeature\\StaticDialog.cpp" = "npp_repo\\PowerEditor\\src\\WinControls\\StaticDialog\\StaticDialog.cpp"
63+
#"src\\DockingFeature\\Window.h" = "npp_repo\\PowerEditor\\src\\WinControls\\Window.h"
64+
#"src\\DockingFeature\\GoToLineDlg.cpp" = "npp_repo\\PowerEditor\\src\\ScintillaComponent\\GoToLineDlg.cpp"
65+
#"src\\DockingFeature\\GoToLineDlg.h" = "npp_repo\\PowerEditor\\src\\ScintillaComponent\\GoToLineDlg.h"
66+
}
67+
#
68+
# loop over each pair, calculate hash of each, and copy any files that are different
69+
#
70+
ForEach ($local_path in $pairs.Keys) {
71+
$upstream_path = $pairs[$local_path]
72+
$local_hash = Get-FileHash $local_path -Algorithm SHA256 | Select-Object -ExpandProperty Hash
73+
$upstream_hash = Get-FileHash $upstream_path -Algorithm SHA256 | Select-Object -ExpandProperty Hash
74+
Write-Output "$local_hash :: hash($local_path)"
75+
Write-Output "$upstream_hash :: hash($upstream_path)"
76+
if ($local_hash -ne $upstream_hash) {
77+
$anyDifference = $true
78+
Copy-Item -Path $upstream_path -destination $local_path -Force
79+
Write-Output "hashes differed, so copied file"
80+
}
81+
}
82+
#
83+
# use GITHUB_OUTPUT to propagate a value that will be able to control the conditional on a future step
84+
if ($anyDifference) {
85+
"ANY_DIFFERENCE=True" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
86+
}
87+
#
88+
# Store the date and head reference for use in subsequent steps
89+
$dateNow = (Get-Date).ToString("yyyy_MMMM_dd")
90+
echo "CHANGE DATE will be $dateNow"
91+
"CHANGE_DATE=$dateNow" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
92+
"HEAD_REF=$(git --git-dir=npp_repo/.git describe --always '@')" | Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append
93+
#
94+
# get rid of the extra hierarchy now that everything necessary has been copied
95+
Remove-Item .\npp_repo -Force -Recurse -ErrorAction SilentlyContinue
96+
#
97+
git status
98+
99+
- name: Commit any updates to the repo
100+
uses: stefanzweifel/git-auto-commit-action@v5
101+
with:
102+
# GitHub will auto-link the upstream ref to the corresponding commit
103+
commit_message: Sync template with notepad-plus-plus/notepad-plus-plus@${{ steps.diff_step.outputs.HEAD_REF }}
104+
105+
- name: If ANY_DIFFERENCE then add MSBuild to PATH
106+
if: ${{steps.diff_step.outputs.ANY_DIFFERENCE}}
107+
uses: microsoft/setup-msbuild@v2
108+
109+
- name: If ANY_DIFFERENCE then run MSBuild of plugin dll
110+
if: ${{steps.diff_step.outputs.ANY_DIFFERENCE}}
111+
working-directory: vs.proj\
112+
run: |
113+
foreach ($target in ('Win32', 'x64', 'ARM64'))
114+
{
115+
msbuild NppPluginTemplate.vcxproj /m /p:configuration=Release /p:platform="$target"
116+
}
117+
118+
- name: Release
119+
if: ${{steps.diff_step.outputs.ANY_DIFFERENCE}}
120+
uses: softprops/action-gh-release@v2
121+
with:
122+
name: Plugin Template for Notepad++ release v${{ steps.diff_step.outputs.CHANGE_DATE }}.${{github.run_number}}.${{github.run_attempt}}
123+
tag_name: v${{ steps.diff_step.outputs.CHANGE_DATE }}.${{github.run_number}}.${{github.run_attempt}}
124+
target_commitish: ${{ github.ref_name }}
125+
token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)