Step 1 - Update Fork and Apply Patches #276
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
name: Step 1 - Update Fork and Apply Patches | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
inputs: | |
force_ci: | |
description: 'Override failure condition to force CI workflow to run' | |
type: boolean | |
default: false | |
required: false | |
push: | |
branches: | |
- main | |
# push: | |
# branches: [ main, feature/** ] | |
# pull_request: | |
# branches: [ main, feature/** ] | |
jobs: | |
update-and-patch-fork: | |
runs-on: ubuntu-latest | |
timeout-minutes: 5 | |
steps: | |
- name: Checkout Fork | |
uses: actions/checkout@v4 | |
with: | |
ref: main | |
fetch-depth: 0 | |
- name: Set up Git | |
run: | | |
git config --global user.name 'GitHub Action' | |
git config --global user.email 'action@github.com' | |
- name: Add Upstream | |
run: git remote add upstream https://github.com/dotnet/vscode-csharp.git | |
- name: Fetch Upstream | |
run: git fetch upstream main | |
- name: Check for Upstream Changes | |
id: check-changes | |
run: | | |
UPSTREAM_COMMITS=$(git rev-list HEAD..upstream/main --count) | |
echo "Upstream commits: $UPSTREAM_COMMITS" | |
echo "UPSTREAM_COMMITS=$UPSTREAM_COMMITS" >> "$GITHUB_OUTPUT" | |
- name: Check Last Run of Step 2 - Build VSIX packages | |
id: check-ci | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const { data: workflows } = await github.rest.actions.listRepoWorkflows({ | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
const ciBuildName = "Step 2 - Build VSIX packages" | |
const ciWorkflow = workflows.workflows.find(workflow => workflow.name === ciBuildName); | |
if (!ciWorkflow) { | |
core.setFailed(`${ciBuildName} workflow not found`); | |
return; | |
} | |
const { data: workflowRuns } = await github.rest.actions.listWorkflowRuns({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
workflow_id: ciWorkflow.id, | |
per_page: 1, | |
status: 'success' | |
}); | |
if (workflowRuns.total_count > 0) { | |
console.log(`The last run of ${ciBuildName} succeeded`); | |
core.setOutput('ci_success', 'true'); | |
} else { | |
console.log(`The last run of ${ciBuildName} did not succeed`); | |
core.setOutput('ci_success', 'false'); | |
} | |
- name: Set Override Failure from Manual Worfklow Dispatch | |
if: github.event_name == 'workflow_dispatch' | |
run: echo "FORCE_CI=${{ github.event.inputs.force_ci }}" >> $GITHUB_ENV | |
- name: Set Override Failure from Commit Message | |
if: github.event_name == 'push' | |
run: | | |
if [[ "$(git log -1 --pretty=%B)" == *"[force-ci]"* ]]; then | |
echo "FORCE_CI=true" >> $GITHUB_ENV | |
else | |
echo "FORCE_CI=false" >> $GITHUB_ENV | |
fi | |
echo $FORCE_CI | |
- name: Get current date/time | |
id: date | |
run: echo "RUN_DATE_TIME=$(date +'%Y-%m-%d %R')" >> "$GITHUB_OUTPUT" | |
- name: Checkout Upstream Changes | |
run: | | |
set -x | |
set -e | |
git checkout upstream/main -- . | |
git reset HEAD .github | |
#git reset HEAD .vscode | |
git restore --staged .github | |
#git restore --staged .vscode | |
git add -- ':!./.github' #':!./.vscode' | |
git commit -m "[pre-patch] Update from upstream at ${{ steps.date.outputs.RUN_DATE_TIME }}" | |
git push origin main | |
- name: Apply Patches | |
run: | | |
PATCHER="___patching/patcher.sh" | |
chmod +x "$PATCHER" | |
. "$PATCHER" | |
- name: Sync/Merge With Upstream | |
run: | | |
set -x | |
set -e | |
git checkout main | |
#git checkout -f HEAD | |
#rm .git/index | |
#git reset | |
git fsck --full --no-dangling | |
git merge --no-commit --no-ff upstream/main | |
git reset -- ./.github | |
#git reset -- ./.vscode | |
- name: Commit & Push Changes | |
run: | | |
set -x | |
set -e | |
git reset HEAD .github | |
#git reset HEAD .vscode | |
git restore --staged .github | |
#git restore --staged .vscode | |
git add -- ':!./.github' #':!./.vscode' | |
git commit -m "[post-patch] patching at ${{ steps.date.outputs.RUN_DATE_TIME }}" | |
git push origin main | |
- name: Skip proceeding to build if no upstream changes and last CI succeeded | |
if: (steps.check-changes.outputs.UPSTREAM_COMMITS == '0' && steps.check-ci.outputs.ci_success == 'true') && env.FORCE_CI != 'true' | |
run: | | |
echo "No changes in upstream repository and the last run of 'Step 2 - Build VSIX packages' succeeded. Failing the workflow." | |
exit 25 |