Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add atomic PR ID job - Callable Workflow #211

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for edge cases
  • Loading branch information
joseph-flinn committed Nov 21, 2023
commit b7bc83835354dd868a4a0c12187439bcac7729d6
5 changes: 1 addition & 4 deletions .github/workflows/_get_pr_id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ name: Get PR ID
on:
workflow_call:
inputs:
repository:
type: string
required: true
commit-sha:
type: string
required: true
Expand All @@ -32,7 +29,7 @@ jobs:
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ inputs.repository }}/commits/${{ inputs.commit-sha }} | \
https://api.github.com/repos/${{ github.repository }}/commits/${{ inputs.commit-sha }} | \
jq -r ".commit.message"
)
ID=$(echo "$commit_message" | head -1 | grep -o "(#.*)" | grep -o "[0-9]*")
Expand Down
60 changes: 53 additions & 7 deletions .github/workflows/test_get_pr_id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,71 @@ on:
- .github/workflows/_get_pr_id.yml
- .github/workflows/test_get_pr_id.yml


jobs:
pr:
main_commit:
uses: .github/workflows/_get_pr_id.yml
with:
repository: "bitwarden/gh-actions"
commit-sha: "7d46c75af91adbfdfc70689f4d8b3405b26bda6b"

test_pr:
name: Test Get PR ID

branch_commit:
uses: .github/workflows/_get_pr_id.yml
with:
commit-sha: "f30be53c2a5b3d61928c0f41a2e25605a9901d6a"


dne_commit:
uses: .github/workflows/_get_pr_id.yml
with:
commit-sha: "f30be53c2a5b3d61928c0f41a2e25605a9901d6b"


test_main_commit:
name: Test Get PR ID - Success
runs-on: ubuntu-22.04
needs:
- pr
- main_commit
steps:
- name: Assert PR ID
- name: Assert
env:
ID: ${{ needs.pr.outputs.id }}
ID: ${{ needs.main_commit.outputs.id }}
run: |
if [[ "$ID" != "196" ]]; then
exit 1
fi

exit 0

test_branch_pr:
name: Test Get PR ID - empty for non-main commit
runs-on: ubuntu-22.04
needs:
- branch_commit
steps:
- name: Assert
env:
ID: ${{ needs.branch_commit.outputs.id }}
run: |
if [[ "$ID" != "" ]]; then
exit 1
fi

exit 0


test_dne_commit:
name: Test Get PR ID - empty for non-existent commit
runs-on: ubuntu-22.04
needs:
- dne_commit
steps:
- name: Assert
env:
ID: ${{ needs.dne_commit.outputs.id }}
run: |
if [[ "$ID" != "" ]]; then
exit 1
fi

exit 0