Travis থেকে মাইগ্রেশন


এখানে একটি উদাহরণ .travis.yml দেওয়া হলো (elm ট্র্যাক থেকে নেওয়া):

sudo: false
language: node_js
node_js:
  - lts/*
script:
  - bin/fetch-configlet
  - bin/configlet lint
  - bin/build.sh

এটিকে দ্রুত GitHub Actions-এ রূপান্তর করতে নিচের ধাপগুলো অনুসরণ করুন:

টেমপ্লেট ভ্যারিয়েবলগুলো নির্ধারণ করুন

variable value
<track> elm
<image-name> ubuntu-latest
<action to setup tooling> actions/setup-node@v1
<install dependencies> npm ci (build.sh-এর ভেতরে হয়)
<code-extensions> .elm

এই সার্চের মাধ্যমে সেটআপ অ্যাকশনটি পাওয়া গেছে। Travis-এর ডিফল্ট ডিস্ট্রিবিউশন দেখে ইমেজের নামটি পাওয়া গেছে।

ধাপগুলো নির্ধারণ করুন

  • bin/fetch-configlet: configlet.yml ওয়ার্কফ্লো ব্যবহার করলে এটির আর প্রয়োজন নেই
  • bin/configlet lint: configlet.yml ওয়ার্কফ্লো ব্যবহার করলে এটির আর প্রয়োজন নেই
  • bin/build.sh: সব কাজ করে দেওয়া একটি একক স্ক্রিপ্ট

"scripts" প্রস্তুত করুন

এই ট্র্যাকটি bin ফোল্ডার ব্যবহার করে, তাই bin ফোল্ডারের ভেতরে নিচের ফাইলগুলো তৈরি করুন:

# bin/pr
bin/build.sh
# bin/pr-check
echo "No checks yet"
# bin/ci
bin/build.sh
# bin/ci-check
echo "No checks yet"

এগুলোকে আলাদা বাইনারি হিসেবে তৈরি করলে পরে অপ্টিমাইজ করার সুযোগ থাকবে। এখনই সবকিছু ইনলাইন করার প্রয়োজন নেই।

টেমপ্লেটগুলো পূরণ করুন

workflows/ci.yml-এর ডিফ হলো এটি।

# # .github/workflows/ci.yml

  # This workflow will do a clean install of node dependencies and run tests across different versions
  #
- # Replace <track> with the track name
- # Replace <image-name> with an image to run the jobs on
- # Replace <action to setup tooling> with a github action to setup tooling on the image
- # Replace <install dependencies> with a cli command to install the dependencies
- # Replace <code-extensions> with file extensions that should trigger the workflow
- #
- # Find Github Actions to setup tooling here:
- # - https://github.com/actions/?q=setup&type=&language=
- # - https://github.com/actions/starter-workflows/tree/main/ci
- # - https://github.com/marketplace?type=actions&query=setup
- #
  # Requires scripts:
- # - scripts/ci-check
- # - scripts/ci
+ # - bin/ci-check
+ # - bin/ci

- name: <track> / main
+ name: elm / main

  on:
    push:
      branches: [main]
    workflow_dispatch:

  jobs:
    precheck:
-     runs-on: <image-name>
+     runs-on: ubuntu-latest

      steps:
        - uses: actions/checkout@v2
-       - name: Use <setup tooling>
-         uses: <action to setup tooling>
+       - name: Use Node LTS
+         uses: actions/setup-node@v1
          with:
-           # here, use the LTS/stable version of the track's tooling
-           # node-version: 12.x
+           node-version: 12.x

        - name: Install project dependencies
-         run: <install dependencies>
+         run: npm ci

-       - name: Run exercism/<track> ci pre-check (checks config, lint code) for all exercises
-         run: scripts/ci-check
+       - name: Run exercism/elm ci pre-check (checks config, lint code) for all exercises
+         run: bin/ci-check

    ci:
-     runs-on: <image-name>
+     runs-on: ubuntu-latest

      strategy:
        matrix:
-         # here, add all SUPPORTED versions only
-         # version: [10.x, 12.x, 14.x]
+         version: [10.x, 12.x, 14.x]

      steps:
        - uses: actions/checkout@v2
-       - name: Use <setup tooling> ${{ matrix.version }}
-         uses: <action to setup tooling>
+       - name: Use Node ${{ matrix.version }}
+         uses: actions/setup-node@v1
          with:
-           # below: see how to inject the version
-           # node-version: ${{ matrix.version }}
+           node-version: ${{ matrix.version }}

        - name: Install project dependencies
-         run: <install dependencies>
+         run: npm ci

-       - name: Run exercism/<track> ci (runs tests) for all exercises
-         run: scripts/ci
+       - name: Run exercism/elm ci (runs tests) for all exercises
+         run: bin/ci

workflows/pr.yml-এও একই পরিবর্তন আছে, তবে একটি উল্লেখযোগ্য ব্যতিক্রম ছাড়া: যে bash-fu প্রতিটি পরিবর্তিত ফাইলকে আর্গুমেন্ট হিসেবে নিয়ে pr-check ও pr স্ক্রিপ্টগুলো কল করে:

# # .github/workflows/pr.yml

# # ...

-       - name: Run exercism/<track> ci pre-check (stub files, config integrity) for changed exercises
+       - name: Run exercism/elm ci pre-check (stub files, config integrity) for changed exercises
          run: |
            PULL_REQUEST_URL=$(jq -r ".pull_request.url" "$GITHUB_EVENT_PATH")
            curl --url $"${PULL_REQUEST_URL}/files" --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | \
-             jq -c '.[] | select(.status == "added" or .status == "modified") | select(.filename | match("\\.(<code-extensions>|md|json)$")) | .filename' | \
+             jq -c '.[] | select(.status == "added" or .status == "modified") | select(.filename | match("\\.(elm|md|json)$")) | .filename' | \
-             xargs -r scripts/pr-check
+             xargs -r bin/pr-check

  # ...

এখন এটি কাজ করা উচিত

GitHub Actions-এ রূপান্তর করার জন্য এটুকুই যথেষ্ট, আর আপনার স্ক্রিপ্টগুলো অপ্টিমাইজ করার সুযোগও থাকবে।

  1. build.sh থেকে যে ধাপগুলো কেবল একবার চলা উচিত সেগুলো সরিয়ে নিয়ে ci-check.sh ও pre-check.sh ফাইলে নিয়ে যান (ইঙ্গিত: আপনি lint.sh তৈরি করে সেটি দুটি "scripts" থেকেই কল করতে পারেন)
  2. pr.sh ও pr-check.sh-এ এমন অপ্টিমাইজেশন যোগ করুন যা ইনপুট আর্গুমেন্ট ব্যবহার করে নির্ধারণ করে কোন ফাইল বা অনুশীলনী যাচাই করতে হবে।
  3. আরও কিছু চেক যোগ করুন
  4. লোকালি চেক চালানোর নিয়ম এবং প্রতিটি চেক কোন কাজ করতে চায়, তা নিয়ে ডকুমেন্টেশন যোগ করুন।