Skip to content

Commit

Permalink
feat: checkout when dryrun
Browse files Browse the repository at this point in the history
  • Loading branch information
guitarrapc committed Jan 7, 2025
1 parent 6d3e78d commit 4c8f56d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/test-update-packagejson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ jobs:
echo -n "FACT: sha for update-packagejson and update-packagejson3 should have same commit id. "
if [[ "${{ needs.update-packagejson.outputs.sha }}" == "${{ needs.update-packagejson3.outputs.sha }}" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi
echo -n "FACT: branch-name for update-packagejson should be expected. "
if [[ "${{ needs.update-packagejson.outputs.branch-name }}" == "test-release/${{ needs.set-tag.outputs.tag }}" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi
echo -n "FACT: branch-name for update-packagejson2 should be exists. "
if [[ "${{ needs.update-packagejson2.outputs.branch-name }}" == "test-release/${{ needs.set-tag.outputs.tag }}" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi
echo -n "FACT: branch-name for update-packagejson3 should be exists. "
if [[ "${{ needs.update-packagejson3.outputs.branch-name }}" == "test-release/v${{ needs.set-tag.outputs.tag }}" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi
cleanup:
if: ${{ needs.update-packagejson3.outputs.is-branch-created == 'true' }}
needs: [update-packagejson3]
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/update-packagejson.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,9 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
branch-name: ${{ steps.update.outputs.branch-name }}
sha: ${{ steps.update.outputs.sha }}
steps:
- name: Configure Output variables
id: configure
run: |
echo "branch-name=test-release/${{ inputs.tag }}" | tee -a "$GITHUB_OUTPUT"
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
Expand Down
9 changes: 9 additions & 0 deletions src/Actions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,26 @@ private async Task GitCommitAsync(bool dryRun, string tag, string email = "41898
var sha = await "git rev-parse HEAD";
GitHubOutput("commited", "0");
GitHubOutput("sha", sha);
GitHubOutput("branch-name", $"");
}
catch (ProcessErrorException)
{
WriteLog("Detected git diff.");
if (dryRun)
{
WriteLog("Dryrun Mode detected, creating branch switch to.");
await $"git switch -c test-release/{tag}";
}

WriteLog("Comming change.");
await $"git config --local user.email \"{email}\"";
await $"git config --local user.name \"{user}\"";
await $"git commit -a -m \"feat: Update package.json to {tag}\" -m \"Commit by [GitHub Actions]({GitHubContext.GetWorkflowRunUrl(GitHubContext.Current)})\"";

var sha = await "git rev-parse HEAD";
GitHubOutput("commited", "1");
GitHubOutput("sha", sha);
GitHubOutput("branch-name", $"test-release/{tag}");
}
}

Expand Down

0 comments on commit 4c8f56d

Please sign in to comment.