feat(unicorn): initital draft #366
Workflow file for this run
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: Unicorn CI/CD pipeline | |
on: | |
workflow_dispatch: | |
create: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- labeled | |
- closed | |
pull_request_review: | |
types: [submitted] | |
concurrency: | |
# See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-a-fallback-value | |
group: push-unicorn${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
defaults: | |
run: | |
shell: bash | |
jobs: | |
check-ready-for-merge-queue: | |
name: Ready for mergequeue | |
# The only way to set different required status checks to a pre-queue and a post-queue , | |
# (i.e. before merging and in merge queue), is to have two jobs with the same name, one that triggers on pull_request, | |
# and another on merge_group. | |
# The 'Ready for mergequeue' which is triggered on pull_request here is a required status to be able to merge | |
# The 'Ready for mergequeue' triggered on merge_group (merge-queue-ci.yml) will block merging untill it has completed with success. | |
# (https://medium.com/@kojoru/how-to-set-up-merge-queues-in-github-actions-59381e5f435a) | |
runs-on: ubuntu-latest | |
outputs: | |
IS_APPROVED: ${{ steps.check-approved.outputs.result }} | |
steps: | |
- name: Check if PR is approved | |
id: check-approved | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
if (!context || !context.payload || !context.payload.pull_request) { | |
return false; | |
} | |
var reviews = await github.rest.pulls.listReviews({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
pull_number: context.issue.number | |
}); | |
if(!reviews || !reviews.data == null) { | |
return false; | |
} | |
var declined = reviews.data.filter(review => review.state != 'APPROVED').length > 0; | |
var pending = context.payload.pull_request.requested_teams.length > 0 | |
console.log(!(declined && pending) ? 'Pr is approved' : 'Pr is not approved'); | |
return !(declined && pending); | |
- name: output | |
run: echo "IS_APPROVED=${{ steps.check-approved.outputs.result }}" >> $GITHUB_OUTPUT | |
# TODO - move this to merge-queue-ci.yml | |
check-unicorn: | |
name: Is this a unicorn PR | |
needs: check-ready-for-merge-queue | |
if: ${{ needs.check-approved.outputs.IS_APPROVED }}" | |
runs-on: ec2-runners | |
container: | |
image: public.ecr.aws/m3u4c4h9/island-is/actions-runner-public:latest | |
timeout-minutes: 10 | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: actions/setup-node@v4 | |
with: | |
node-version-file: 'package.json' | |
- name: Setup yarn | |
run: corepack enable | |
- name: Get cache | |
id: get-cache | |
uses: ./.github/actions/get-cache | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
enable-cache: 'node_modules,generated-files' | |
- name: Check unicorn affected | |
id: unicorn-affected | |
env: | |
BaseRef: ${{ github.base_ref }} #The target branch e.g. main (feature/unicorn-app) | |
HeadRef: ${{ github.head_ref }} #The branch being merged e.g. (unicorn-pipe-rel3) | |
run: | | |
echo "Comparing nx affected for $HeadRef using origin/$BaseRef as base branch" | |
echo IS_UNICORN=$(node scripts/ci/unicorn-utils.mjs "{\"baseBranch\": \"origin/$BaseRef\", \"mergeBranch\": \"$HeadRef\" }") >> "$GITHUB_OUTPUT" | |
- name: Results | |
run: | | |
echo "Unicorn = ${{ steps.unicorn-affected.outputs.IS_UNICORN }}" | |
- name: Find Latest Release Branch | |
id: get_latest_release | |
run: | | |
node scripts/ci/get-last-release.mjs $(git branch -r) | |
- run: "echo 'latest release: ${{ steps.get_latest_release.outputs.data }}'" |