feat: replace Bash to C# Batch #321
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: Test clean-packagejson-branch | |
on: | |
workflow_dispatch: | |
pull_request: | |
branches: ["main"] | |
push: | |
branches: ["main"] | |
jobs: | |
create-branch: | |
runs-on: ubuntu-latest | |
outputs: | |
branch-name: ${{ steps.branch.outputs.name }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set branch name | |
id: branch | |
run: echo "name=test-branch-${{ github.run_id }}" | tee -a "$GITHUB_OUTPUT" | |
- name: Add some file change | |
run: echo "test" > test.txt | |
- name: Create branch | |
run: | | |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git config --local user.name "github-actions[bot]" | |
git switch -c ${{ steps.branch.outputs.name }} | |
git add . | |
git commit -m "test" | |
git push origin ${{ steps.branch.outputs.name }} | |
cleanup: | |
needs: [create-branch] | |
uses: ./.github/workflows/clean-packagejson-branch.yaml | |
with: | |
branch: ${{ needs.create-branch.outputs.branch-name }} | |
cleanup2: | |
needs: [create-branch, cleanup] | |
uses: ./.github/workflows/clean-packagejson-branch.yaml | |
with: | |
branch: ${{ needs.create-branch.outputs.branch-name }} | |
test: | |
needs: [create-branch, cleanup, cleanup2] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Branch list | |
run: gh api /repos/${{ github.repository }}/branches | jq | |
- name: Test branch deleted | |
run: | | |
echo "DEBUG: cleanup : ${{ needs.cleanup.outputs.branch-deleted }}" | |
echo "DEBUG: cleanup2: ${{ needs.cleanup2.outputs.branch-deleted }}" | |
echo -n "FACT: cleanup deleted branch. " | |
if [[ "${{ needs.cleanup.outputs.branch-deleted }}" == "true" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi | |
echo -n "FACT: cleanup2 skip delete branch. " | |
if [[ "${{ needs.cleanup2.outputs.branch-deleted }}" != "true" ]]; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi | |
echo -n "FACT: remote branch should not exists. " | |
if ! gh api /repos/${{ github.repository }}/branches | jq -r '.[].name' | grep "${{ needs.create-branch.outputs.branch-name }}" >/dev/null; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi | |
echo -n "FACT: remote branch should not retrieve. " | |
if ! gh api /repos/${{ github.repository }}/branches/${{ needs.create-branch.outputs.branch-name }} >/dev/null 2>&1; then echo "[O PASS]"; else echo "[X FAIL]" && exit 1; fi | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} # auto generated token | |
actions-timeline: | |
needs: [create-branch, cleanup, cleanup2, test] | |
uses: ./.github/workflows/actions-timeline.yaml | |
secrets: inherit |