-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #408 from kosenda/feature/circleci-roborazzi
Roborazziを使って画面の差分を出せるようにする
- Loading branch information
Showing
2 changed files
with
141 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ version: 2.1 | |
|
||
orbs: | ||
slack: circleci/[email protected] | ||
gh: circleci/[email protected] | ||
aws-cli: circleci/[email protected] | ||
aws-s3: circleci/[email protected] | ||
|
||
executors: | ||
android: | ||
|
@@ -29,11 +32,77 @@ commands: | |
- ~/.gradle | ||
key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "app/build.gradle.kts" }} | ||
|
||
set-github-access-token: | ||
steps: | ||
- run: | ||
name: set github access token | ||
# Create GitHub App Token using JWT and pass it with gh auth to login | ||
# ref: https://zenn.dev/gorohash/articles/e2c5f6ce50f4e6 | ||
command: | | ||
# ◼ create JWT | ||
echo create JWT | ||
# ◼◼ header | ||
header=$(echo -n '{"alg":"RS256","typ":"JWT"}' | base64 -w 0) | ||
# Current Unix time(Epoch) | ||
now=$(date "+%s") | ||
# Date and time token was issued (issued at) (Set 1 minute before the current time to account for the possibility of the clock being off) | ||
iat=$((${now} - 60)) | ||
# Date and time when token expires (Expiration time) (10 minutes later) | ||
exp=$((${now} + (10 * 60))) | ||
# ◼◼ payload | ||
# iss: GitHub App ID (issuer) | ||
iss="$APP_ID" | ||
payload=$(echo -n "{\"iat\":${iat},\"exp\":${exp},\"iss\":${iss}}" | base64 -w 0) | ||
# ◼◼ signature | ||
echo $COMMENT_GITHUB_API_TOKEN | base64 --decode > ./githubapps | ||
signature=$(echo -n $(echo -n "${header}.${payload}" | openssl dgst -binary -sha256 -sign "./githubapps" | base64)) | ||
rm ./githubapps | ||
# ◼◼ jwt | ||
jwt="${header}.${payload}.${signature}" | ||
# ◼ Generating an installation access token for a GitHub App | ||
echo Generating an installation access token for a GitHub App | ||
user_name="kosenda" | ||
installation_id=$( | ||
curl -s -G \ | ||
-H "Authorization: Bearer ${jwt}" \ | ||
-H "Accept: application/vnd.github+json" \ | ||
"https://api.github.com/app/installations" \ | ||
| jq -r ".[] | select(.account.login == \"${user_name}\" and .account.type == \"User\") | .id" | ||
) | ||
# ◼ Get an installation access token | ||
echo Get an installation access token | ||
access_token=$( | ||
echo $( | ||
curl -s -X POST \ | ||
-H "Authorization: Bearer ${jwt}" \ | ||
-H "Accept: application/vnd.github+json" \ | ||
"https://api.github.com/app/installations/${installation_id}/access_tokens" \ | ||
| jq -r ".token" | ||
) | ||
) | ||
# ◼ set github access token | ||
echo "export GITHUB_ACCESS_TOKEN='$access_token'" >> $BASH_ENV | ||
jobs: | ||
build-and-test-prod: | ||
executor: android | ||
steps: | ||
- checkout | ||
- gh/install | ||
- set-github-access-token | ||
- run: | ||
name: gh login | ||
command: echo "$GITHUB_ACCESS_TOKEN" | gh auth login --with-token | ||
- run: | ||
name: get base branch name | ||
# ref: https://discuss.circleci.com/t/how-to-retrieve-a-pull-requests-base-branch-name-github/36911 | ||
command: | | ||
# ◼ get base branch name | ||
pr=$(echo https://api.github.com/repos/${CIRCLE_PULL_REQUEST:19} | sed "s/\/pull\//\/pulls\//") | ||
base=$(curl -s -H "Authorization: token ${GITHUB_ACCESS_TOKEN}" $pr | jq '.base.ref') | ||
echo "base branch name: $base" | ||
echo "export BASE_BRANCH_NAME=${base}" >> $BASH_ENV | ||
- set-locale-properties | ||
- restore-and-save-gradle-cache | ||
- run: | ||
|
@@ -51,6 +120,17 @@ jobs: | |
- run: | ||
name: test | ||
command: ./gradlew testProdDebug --stacktrace | ||
- aws-cli/setup: | ||
aws_access_key_id: AWS_ACCESS_KEY_ID | ||
aws_secret_access_key: AWS_SECRET_ACCESS_KEY | ||
region: AWS_REGION | ||
- aws-s3/copy: | ||
arguments: --recursive | ||
from: "s3://hiraganaconverter-roborazzi/image/$BASE_BRANCH_NAME" | ||
to: ./app/build/outputs/roborazzi | ||
- run: | ||
name: compare screenshots | ||
command: ./gradlew compareRoborazziProdDebug --stacktrace | ||
- run: | ||
name: jacoco-report | ||
command: ./gradlew jacocoTestReport | ||
|
@@ -62,6 +142,35 @@ jobs: | |
- run: | ||
name: run-danger-file | ||
command: bundle exec danger --verbose | ||
- run: | ||
name: move screenshots files | ||
command: | | ||
mkdir -p ./build/outputs/roborazzi/compareProdDebug | ||
mv ./app/build/outputs/roborazzi ./build/outputs/roborazzi/compareProdDebug | ||
- run: | ||
name: create comments | ||
command: | | ||
# create comments | ||
cat \<< EOF > comments | ||
|fileName|image| | ||
|---|---| | ||
EOF | ||
# Find all the files ending with _compare.png | ||
files_to_add=$(find . -type f -path "./build/outputs/roborazzi/compareProdDebug/roborazzi/*" -name "*_compare.png") | ||
# Add compare image | ||
for file in $files_to_add; do | ||
if [[ "$file" =~ ^[a-zA-Z0-9_./-]+$ ]]; then | ||
echo "base name: $(basename $file)" | ||
base_name=$(basename $file) | ||
name=$(echo $base_name | rev | cut -d. -f-2 | rev ) | ||
echo "| $name | <img src=\"https://hiraganaconverter-roborazzi.s3.ap-northeast-1.amazonaws.com/image/$base_name\" width=\"600\"> |" >> comments | ||
fi | ||
done | ||
- run: | ||
name: test comment | ||
command: gh pr comment "$CIRCLE_PULL_REQUEST" --edit-last -F ./comments || gh pr comment "$CIRCLE_PULL_REQUEST" -F ./comments | ||
- slack/notify: | ||
event: fail | ||
template: basic_fail_1 | ||
|
@@ -82,13 +191,35 @@ jobs: | |
event: fail | ||
template: basic_fail_1 | ||
|
||
save-screen-shot: | ||
executor: android | ||
steps: | ||
- checkout | ||
- set-locale-properties | ||
- restore-and-save-gradle-cache | ||
- run: | ||
name: create screenshots | ||
command: ./gradlew recordRoborazziMockDebug --stacktrace | ||
- aws-cli/setup: | ||
aws_access_key_id: AWS_ACCESS_KEY_ID | ||
aws_secret_access_key: AWS_SECRET_ACCESS_KEY | ||
region: AWS_REGION | ||
- aws-s3/sync: | ||
from: ./app/build/outputs/roborazzi | ||
to: s3://hiraganaconverter-roborazzi/image/$CIRCLE_BRANCH | ||
|
||
workflows: | ||
test: | ||
jobs: | ||
- build-and-test-prod: | ||
context: slack-secrets | ||
- build-mock: | ||
context: slack-secrets | ||
|
||
- save-screen-shot: | ||
filters: | ||
branches: | ||
only: | ||
- main | ||
- develop | ||
# ■ memo ■ | ||
# check command: circleci config validate |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.