-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a shared code sync action (#4008)
- Loading branch information
Showing
7 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Check the code is in sync | ||
$changed = (select-string "nothing to commit" artifacts\status.txt).count -eq 0 | ||
return $changed |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
name: Azure->Dotnet Extensions Code Sync | ||
on: | ||
# Manual run | ||
workflow_dispatch: | ||
|
||
permissions: | ||
contents: write | ||
issues: write | ||
pull-requests: write | ||
|
||
jobs: | ||
compare_repos: | ||
# Comment out this line to test the scripts in a fork | ||
if: github.repository == 'dotnet/extensions' | ||
name: Sync shared code between Azure and DotNet | ||
runs-on: windows-latest | ||
steps: | ||
- name: Checkout dotnet/extensions | ||
uses: actions/checkout@v3 | ||
with: | ||
# Test this script using changes in a fork | ||
repository: 'dotnet/extensions' | ||
path: dotnet-extensions | ||
ref: main | ||
- name: Checkout azure/dotnet-extensions-experimental | ||
uses: actions/checkout@v3 | ||
with: | ||
# Test this script using changes in a fork | ||
repository: 'azure/dotnet-extensions-experimental' | ||
path: azure-extensions | ||
ref: main | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Copy | ||
shell: cmd | ||
working-directory: .\azure-extensions\src\Shared\DotNetSync\ | ||
env: | ||
DOTNETEXTENSIONS_REPO: d:\a\extensions\extensions\dotnet-extensions\ | ||
run: CopyToDotNet.cmd | ||
- name: Diff | ||
shell: cmd | ||
working-directory: .\dotnet-extensions\ | ||
run: | | ||
mkdir ..\artifacts | ||
git status > ..\artifacts\status.txt | ||
git diff > ..\artifacts\diff.txt | ||
- uses: actions/upload-artifact@v3 | ||
with: | ||
name: results | ||
path: artifacts | ||
- name: Check | ||
id: check | ||
shell: pwsh | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
$sendpr = .\dotnet-extensions\.github\workflows\azure-sync-checkdiff.ps1 | ||
echo "sendpr=$sendpr" >> $env:GITHUB_OUTPUT | ||
- name: Send PR | ||
if: steps.check.outputs.sendpr == 'true' | ||
# https://github.com/marketplace/actions/create-pull-request | ||
uses: dotnet/actions-create-pull-request@v4 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
path: .\dotnet-extensions | ||
commit-message: 'Sync shared code from azure/dotnet-extensions-experimental' | ||
title: 'Sync shared code from azure/dotnet-extensions-experimental' | ||
body: 'This PR was automatically generated to sync shared code changes from azure/dotnet-extensions-experimental. Fixes https://github.com/azure/dotnet-extensions-experimental/issues/1.' | ||
base: main | ||
branch: github-action/sync-azure | ||
branch-suffix: timestamp |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@ECHO OFF | ||
SETLOCAL | ||
|
||
if not [%1] == [] (set remote_repo=%1) else (set remote_repo=%AZUREEXTENSIONS_REPO%) | ||
|
||
IF [%remote_repo%] == [] ( | ||
echo The 'AZUREEXTENSIONS_REPO' environment variable or command line parameter is not set, aborting. | ||
exit /b 1 | ||
) | ||
|
||
echo AZUREEXTENSIONS_REPO: %remote_repo% | ||
|
||
REM https://superuser.com/questions/280425/getting-robocopy-to-return-a-proper-exit-code | ||
IF %ERRORLEVEL% LSS 8 (robocopy ..\Data.Validation\ %remote_repo%\src\Shared\Data.Validation\ /MIR) | ||
IF %ERRORLEVEL% LSS 8 (robocopy ..\AzureSync\ %remote_repo%\src\Shared\DotNetSync\ /MIR) | ||
IF %ERRORLEVEL% LSS 8 (robocopy ..\EmptyCollections\ %remote_repo%\src\Shared\EmptyCollections\ /MIR) | ||
IF %ERRORLEVEL% LSS 8 (robocopy ..\NumericExtensions\ %remote_repo%\src\Shared\NumericExtensions\ /MIR) | ||
IF %ERRORLEVEL% LSS 8 (robocopy ..\Throw\ %remote_repo%\src\Shared\Throw\ /MIR) | ||
|
||
rem 0x0-4 mean everythings good, files may have been copied. 0x08-10 mean are actual errors. | ||
echo ErrorLevel = %ERRORLEVEL% | ||
IF %ERRORLEVEL% LSS 8 (exit /b 0) ELSE (exit 1) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ -n "$1" ]]; then | ||
remote_repo="$1" | ||
else | ||
remote_repo="$AZUREEXTENSIONS_REPO" | ||
fi | ||
|
||
if [[ -z "$remote_repo" ]]; then | ||
echo The 'AZUREEXTENSIONS_REPO' environment variable or command line parameter is not set, aborting. | ||
exit 1 | ||
fi | ||
|
||
cd "$(dirname "$0")" || exit 1 | ||
|
||
echo "AZUREEXTENSIONS_REPO: $remote_repo" | ||
|
||
rsync -av --delete ../Data.Validation/ "$remote_repo"/src/Shared/Data.Validation/ | ||
rsync -av --delete ../AzureSync/ "$remote_repo"/src/Shared/DotNetSync/ | ||
rsync -av --delete ../EmptyCollections/ "$remote_repo"/src/Shared/EmptyCollections/ | ||
rsync -av --delete ../NumericExtensions/ "$remote_repo"/src/Shared/NumericExtensions/ | ||
rsync -av --delete ../Throw/ "$remote_repo"/src/Shared/Throw/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bash | ||
|
||
if [[ -n "$1" ]]; then | ||
remote_repo="$1" | ||
else | ||
remote_repo="$DOTNETEXTENSIONS_REPO" | ||
fi | ||
|
||
if [[ -z "$remote_repo" ]]; then | ||
echo The 'DOTNETEXTENSIONS_REPO' environment variable or command line parameter is not set, aborting. | ||
exit 1 | ||
fi | ||
|
||
cd "$(dirname "$0")" || exit 1 | ||
|
||
echo "DOTNETEXTENSIONS_REPO: $remote_repo" | ||
|
||
rsync -av --delete ../Data.Validation/ "$remote_repo"/src/Shared/Data.Validation/ | ||
rsync -av --delete ../DotNetSync/ "$remote_repo"/src/Shared/AzureSync/ | ||
rsync -av --delete ../EmptyCollections/ "$remote_repo"/src/Shared/EmptyCollections/ | ||
rsync -av --delete ../NumericExtensions/ "$remote_repo"/src/Shared/NumericExtensions/ | ||
rsync -av --delete ../Throw/ "$remote_repo"/src/Shared/Throw/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
@ECHO OFF | ||
SETLOCAL | ||
|
||
if not [%1] == [] (set remote_repo=%1) else (set remote_repo=%DOTNETEXTENSIONS_REPO%) | ||
|
||
IF [%remote_repo%] == [] ( | ||
echo The 'DOTNETEXTENSIONS_REPO' environment variable or command line parameter is not set, aborting. | ||
exit /b 1 | ||
) | ||
|
||
echo DOTNETEXTENSIONS_REPO: %remote_repo% | ||
|
||
REM https://superuser.com/questions/280425/getting-robocopy-to-return-a-proper-exit-code | ||
IF %ERRORLEVEL% LSS 8 (robocopy ..\DotNetSync\ %remote_repo%\src\Shared\AzureSync\ /MIR) | ||
IF %ERRORLEVEL% LSS 8 (robocopy ..\Data.Validation\ %remote_repo%\src\Shared\Data.Validation\ /MIR) | ||
IF %ERRORLEVEL% LSS 8 (robocopy ..\EmptyCollections\ %remote_repo%\src\Shared\EmptyCollections\ /MIR) | ||
IF %ERRORLEVEL% LSS 8 (robocopy ..\NumericExtensions\ %remote_repo%\src\Shared\NumericExtensions\ /MIR) | ||
IF %ERRORLEVEL% LSS 8 (robocopy ..\Throw\ %remote_repo%\src\Shared\Throw\ /MIR) | ||
|
||
rem 0x0-4 mean everythings good, files may have been copied. 0x08-10 mean are actual errors. | ||
echo ErrorLevel = %ERRORLEVEL% | ||
IF %ERRORLEVEL% LSS 8 (exit /b 0) ELSE (exit 1) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
The code in this directory is shared between dotnet/extensions and azure/dotnet-extensions-experimental. This contains shared sources used in both repos. Any changes to this dir need to be checked into both repositories. | ||
|
||
dotnet/extensions code paths: | ||
- extensions\src\shared\ | ||
|
||
azure/dotnet-extensions-experimental code paths: | ||
- dotnet-extensions-experimental\src\shared\ | ||
|
||
## Copying code | ||
- To copy code from dotnet/extensions to azure/dotnet-extensions-experimental, set AZUREEXTENSIONS_REPO to the azure repo root and then run CopyToAzure.cmd. | ||
- To copy code from azure/dotnet-extensions-experimental to dotnet/extensions, set DOTNETEXTENSIONS_REPO to the dotnet repo root and then run CopyToDotnet.cmd. | ||
|
||
## GitHub Actions | ||
|
||
In azure/dotnet-extensions-experimental, the [dotnet-sync](https://github.com/Azure/dotnet-extensions-experimental/actions/workflows/dotnet-sync.yml) GitHub action automatically creates PRs to pull in changes from dotnet/runtime. | ||
|
||
In dotnet/extensions, the [azure-sync](https://github.com/dotnet/extensions/actions/workflows/azure-sync.yml) GitHub action must be run **manually** to create PRs to pull in changes from azure/dotnet-extensions-experimental. | ||
This is expected to be less common. |