DEV Community

Cover image for AppStore Connect API ใหม่ กับ fastlane เจ้าเดิม
Wasith Theerapattrathamrong
Wasith Theerapattrathamrong

Posted on

2 1

AppStore Connect API ใหม่ กับ fastlane เจ้าเดิม

หลังจากที่ AppStore Connect เปลี่ยน API เลิกการใช้ Username, password, OTP, และ app-password ไปทำให้ถึงเวลาที่ fastlane ต้องยกเครื่อง ต้องใช้ fastlane 2.162.0 ขึ้นไปเท่านั้น

Create API KEY

ขั้นแรกเราต้องเข้าไปที่ https://appstoreconnect.apple.com/access/api ก่อน หรือ

  1. Login ที่ https://appstoreconnect.apple.com ครั้งแรกที่ทำต้องใช้ Account Holder เท่านั้น ใช้ Admin ไม่พอนะ ใครที่ทำหายไปแล้วไปตามหามาด้วย
  2. เข้าไปที่ https://appstoreconnect.apple.com/access/api หรือ Login > Users and Access > Keys >
  3. กด Request Access

Screen Shot 2563-10-13 at 08.09.08

  1. อ่านให้เรียบร้อย แล้วติ๊กยอมรับ แล้วกด Submit หลังจากตรงนี้ใช้ Admin ขึ้นไปได้ละ

Screen Shot 2563-10-13 at 08.10.04

  1. กด Generate API Key
  2. ตั้งชื่อ เช่น Fastlane, Access เลือกเป็น level ของ user ที่เราจะให้ใช้ API Key ตัวที่กำลังจะสร้าง เลือก Developer หรือ Admin​ ไม่เป็นไรถ้าสร้างแล้วใช้ไม่ได้มาสร้างใหม่ได้เรื่อย ๆ
  3. กด Download API Key ดาวโหลดได้ครั้งเดียวนะ ทำหายให้ Revoke แล้วสร้างใหม่

Screen Shot 2563-10-13 at 08.13.55

  1. เอา key ที่ได้มาไปเก็บไว้ที่ปลอดภัย เช่น AWS Key Management แต่ถ้า ไม่ได้สนใจ security อะไรมากก็โพสขึ้่น pantip (หยอกนะ)

Create JSON file for App Store config in Fastlane

ต่อมาเราจะมาสร้าง .json file ที่เก็บตัวข้อมูลที่ใช้ในการต่อกับ App Store Connect

{
"key_id": "<KEY_ID>",
"issuer_id": "<ISSURE_ID>",
"key": "-----BEGIN PRIVATE KEY-----\nKEY_PART1\nKEY_PART2\n...\n-----END PRIVATE KEY-----",
"duration": 1200,
"in_house": false
}

โดยให้แทนค่า KEY_ID, ISSUE_ID ที่มาจากหน้า https://appstoreconnect.apple.com/access/api หนะแหละ แล้วเปิดไว้ .p8 ที่ดาวโหลดมาได้แล้วเอาไปแทน value ตรง key และแทนการขึ้นบรรทัดใหม่ด้วยการ \n

Use it

เหมือนเดิมเอาไปวางไว้ใน Key Management หรือ เอาง่าย ๆ ก็วางไว้กับ Fastfile เลยก็ได้ ในกรณีนี้วางไว้ที่ fastlane/app-store-connect.json

เสร็จแล้วใน Deliverfile, Matchfile, Precheckfile, หรือไฟล์ที่เกี่ยวกับ App Store Connect ว่า api_key_path("fastlane/app-store-connect.json")

เท่านี้ก็ใช้งานได้แล้ว ให้ลองใช้ distribute, match อะไรพวกนี้ดูว่าสามารถใช้งานได้หรือไม่

ปล.

จริง ๆ มีอีกวิธีคือเขียน Code ใน Fastfile แต่เราพบว่า code มันยั๊วเยี๊ยไปหมด เราเลยนำเสนอแค่แบบการใช้ config json เท่านั้น

ถ้าใครเจอ Unresolved conflict between options: 'api_key' and 'username' ให้ลองลบพวก username หรือ FASTLANE_USERNAME ออกไปเพราะมันชนกัน

Reference:

Playwright CLI Flags Tutorial

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • --last-failed: Zero in on just the tests that failed in your previous run
  • --only-changed: Test only the spec files you've modified in git
  • --repeat-each: Run tests multiple times to catch flaky behavior before it reaches production
  • --forbid-only: Prevent accidental test.only commits from breaking your CI pipeline
  • --ui --headed --workers 1: Debug visually with browser windows and sequential test execution

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Practical examples included!

Watch Video 📹️

Top comments (0)

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay