Unicorn CI/CD pipeline #349
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: | |
printJob: | |
name: Print event | |
runs-on: ubuntu-latest | |
steps: | |
- name: Dump GitHub context | |
env: | |
GITHUB_CONTEXT: ${{ toJson(github) }} | |
run: | | |
echo "$GITHUB_CONTEXT" | |
check-ready-for-merge-queue: | |
name: Ready for mergequeue | |
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 | |
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 | |
run: | | |
node scripts/ci/get-last-release.mjs $(git branch -r) | |
- run: "echo 'latest release: ${{ steps.get_latest_release.outputs.data }}'" |