Skip to content

Commit

Permalink
add canary workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
sugarmanz committed Dec 6, 2022
1 parent 92002b6 commit 039f2f8
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 26 deletions.
68 changes: 42 additions & 26 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
version: 2.1

parameters:
GHA_Actor:
type: string
default: ""
GHA_Action:
type: string
default: ""
GHA_Event:
type: string
default: ""
GHA_Meta:
type: string
default: ""
should_release:
type: boolean
default: false

orbs:
macos: circleci/macos@2
Expand Down Expand Up @@ -42,6 +36,28 @@ executors:
environment:
TZ: "/usr/share/zoneinfo/America/Los_Angeles"

commands:
auto_shipit:
description: Perform Auto shipit
steps:
- attach_workspace:
at: ~/player

- restore_cache:
keys:
- v1-bazel-cache-core-{{ .Branch }}-{{ .Revision }}
- v1-bazel-cache-core-{{ .Branch }}
- v1-bazel-cache-core-main
- gem-v1-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- gem-v1-{{ arch }}-main-{{ checksum "Gemfile.lock" }}

- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run: echo -e $GPG_KEY | gpg --import --batch
- run: |
source ~/.bashrc
bundle install
npx auto shipit --only-graduate-with-release-label -vv
jobs:
setup:
executor: base
Expand Down Expand Up @@ -245,26 +261,19 @@ jobs:
- codecov/upload:
file: ./bazel-out/_coverage/_coverage_report.dat

release:
maybe_release:
executor: base
steps:
- attach_workspace:
at: ~/player

- restore_cache:
keys:
- v1-bazel-cache-core-{{ .Branch }}-{{ .Revision }}
- v1-bazel-cache-core-{{ .Branch }}
- v1-bazel-cache-core-main
- gem-v1-{{ arch }}-{{ .Branch }}-{{ checksum "Gemfile.lock" }}
- gem-v1-{{ arch }}-main-{{ checksum "Gemfile.lock" }}
- run: echo "Should I release? (<< pipeline.parameters.should_release >>)"
- when:
condition: << pipeline.parameters.should_release >>
steps:
- auto_shipit

- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
- run: echo -e $GPG_KEY | gpg --import --batch
- run: |
source ~/.bashrc
bundle install
npx auto shipit --only-graduate-with-release-label -vv
release:
executor: base
steps:
- auto_shipit

applitools_init:
executor: base
Expand Down Expand Up @@ -315,6 +324,13 @@ workflows:
- applitools_init
- bazelrc

- maybe_release:
context:
- Publish
requires:
- build
- build_ios

- test:
requires:
- build
Expand Down
99 changes: 99 additions & 0 deletions .github/workflows/canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Publish canary on PR comment

on:
issue_comment:
types:
- created

jobs:
check_auth:
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request && github.event.comment.body == '/canary' }}
steps:
- name: Check auth
id: check_auth
uses: actions/github-script@v6
with:
result-encoding: string
github-token: ${{ secrets.GH_TOKEN }}
script: |
const { owner, repo } = context.issue;
const { login: username } = context.payload.comment.user;
await github.rest.repos.checkCollaborator({
owner,
repo,
username,
});
github.rest.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: "eyes",
});
const { number: pull_number } = context.payload.issue;
const { data: { head: { ref: branch }}} = await github.rest.pulls.get({
owner,
repo,
pull_number,
});
return branch;
- name: Not a collaborator
if: ${{ failure() }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const { owner, repo, number: issue_number } = context.issue;
github.rest.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: "-1",
});
github.rest.issues.createComment({
owner,
repo,
issue_number,
body: 'Canary builds can only be requested by collaborators. Please tag a maintainer to request a canary build. ❌',
});
outputs:
branch: ${{ steps.check_auth.outputs.result }}

trigger_canary:
runs-on: ubuntu-latest
needs: check_auth
steps:
- name: Trigger canary build
run: |
curl --no-progress-meter --fail --request POST \
--url https://circleci.com/api/v2/project/gh/${{ github.repository }}/pipeline \
--header 'Circle-Token: ${{ secrets.CCI_TOKEN }}' \
--header 'content-type: application/json' \
--header 'x-attribution-login: ${{ github.actor }}' \
--header 'x-attribution-actor-id: ${{ github.actor }}' \
--data '{ "branch": "${{ needs.check_auth.outputs.branch }}", "parameters": { "should_release": true }}'
- name: Trigger success
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const { owner, repo } = context.issue;
github.rest.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: "rocket",
});
- name: Trigger failed
if: ${{ failure() }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GH_TOKEN }}
script: |
const { owner, repo } = context.issue;
github.rest.reactions.createForIssueComment({
owner,
repo,
comment_id: context.payload.comment.id,
content: "confused",
});

0 comments on commit 039f2f8

Please sign in to comment.