Μετάβαση από Travis


Ορίστε ένα παράδειγμα .travis.yml (παρμένο από το track elm):

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

Για να το μετατρέψεις γρήγορα σε GitHub Actions, ακολούθησε τα παρακάτω βήματα:

Καθόρισε τις μεταβλητές του προτύπου

μεταβλητή τιμή
<track> elm
<image-name> ubuntu-latest
<action to setup tooling> actions/setup-node@v1
<install dependencies> npm ci (γίνεται μέσα στο build.sh)
<code-extensions> .elm

Βρήκα το action ρύθμισης μέσω αυτής της αναζήτησης. Βρήκα το όνομα της εικόνας κοιτάζοντας την προεπιλεγμένη διανομή του Travis.

Καθόρισε τα βήματα

  • bin/fetch-configlet: δεν το χρειάζεσαι πια όταν χρησιμοποιείς το workflow configlet.yml
  • bin/configlet lint: δεν το χρειάζεσαι πια όταν χρησιμοποιείς το workflow configlet.yml
  • bin/build.sh: ένα μόνο script που κάνει τα πάντα

Ετοίμασε τα "scripts"

Αυτό το track χρησιμοποιεί τον φάκελο 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"

Αν τα δημιουργήσεις ως ξεχωριστά εκτελέσιμα, θα μπορείς να τα βελτιστοποιήσεις αργότερα. Δεν χρειάζεται να κάνεις τίποτα inline για την ώρα.

Συμπλήρωσε τα πρότυπα

Ορίστε το diff για το 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 που καλεί τα script 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, με τη δυνατότητα να βελτιστοποιήσεις τα script σου.

  1. Από το build.sh, αφαίρεσε τα βήματα που πρέπει να εκτελούνται μόνο μία φορά και μετέφερέ τα στα αρχεία ci-check.sh και pre-check.sh (υπόδειξη: μπορείς να δημιουργήσεις το lint.sh και να το καλείς και από τα δύο "scripts")
  2. Στα pr.sh και pr-check.sh, πρόσθεσε βελτιστοποιήσεις που χρησιμοποιούν τα ορίσματα εισόδου για να καθορίσουν ποια αρχεία ή ασκήσεις θα ελεγχθούν.
  3. Πρόσθεσε επιπλέον ελέγχους
  4. Πρόσθεσε τεκμηρίωση για το πώς να τρέχεις τους ελέγχους τοπικά και τι προσπαθεί να πετύχει ο καθένας.