github.com/KEINOS/go-countline@v1.1.0/.github/workflows/version-tests.yaml (about)

     1  # =============================================================================
     2  #  Unit Tests on Go v1.16 to latest
     3  # =============================================================================
     4  # This Workflow runs unit tests on various Go versions over Docker on any push.
     5  # This action caches the built Docker image for a month unless any changes in
     6  # the Dockerfile or go.mod were made.
     7  name: Go 1.16~latest
     8  
     9  on:
    10    workflow_dispatch:
    11    push:
    12  
    13  env:
    14    PATH_CACHE: /tmp/docker-img-arch
    15  
    16  jobs:
    17    go:
    18      name: Run tests on various Go versions via container
    19      runs-on: ubuntu-latest
    20      steps:
    21        - name: Checkout repo
    22          uses: actions/checkout@v3
    23  
    24        - name: Create cache ID from file hash
    25          uses: KEINOS/gh-action-hash-for-cache@main
    26          id: cacheid
    27          # Udate the hash if any file in the path is changed or the month has changed.
    28          with:
    29            path: |
    30              ./go.mod
    31              ./.github/Dockerfile
    32              ./.github/docker-compose.yml
    33              ./.github/workflows/version-tests.yaml
    34            variant: $(TZ=UTC-9 date '+%Y%m')
    35  
    36        - name: Cache or restore image archive
    37          id: cache
    38          uses: actions/cache@v3
    39          with:
    40            path: ${{ env.PATH_CACHE }}
    41            key: ${{ steps.cacheid.outputs.hash }}
    42  
    43        - name: Load Docker images if exist
    44          if: steps.cache.outputs.cache-hit == 'true'
    45          run: |
    46            docker load --input ${{ env.PATH_CACHE }}/github_v1_16_1.tar
    47            docker load --input ${{ env.PATH_CACHE }}/github_v1_17_1.tar
    48            docker load --input ${{ env.PATH_CACHE }}/github_v1_18_1.tar
    49            docker load --input ${{ env.PATH_CACHE }}/github_v1_19_1.tar
    50            docker load --input ${{ env.PATH_CACHE }}/github_latest_1.tar
    51  
    52        - name: Build Docker images if no-exists
    53          if: steps.cache.outputs.cache-hit != 'true'
    54          run: |
    55            : # Pull images one-by-one for stability
    56            docker pull golang:1.16-alpine
    57            docker pull golang:1.17-alpine
    58            docker pull golang:1.18-alpine
    59            docker pull golang:1.19-alpine
    60            docker pull golang:alpine
    61            : # Build container images
    62            docker-compose --file ./.github/docker-compose.yml build
    63  
    64        - name: Save built images if no-exists
    65          if: steps.cache.outputs.cache-hit != 'true'
    66          run: |
    67            : # Ensure the directory exists
    68            mkdir -p ${{ env.PATH_CACHE }}
    69            : # Save images to cache directory
    70            docker save --output ${{ env.PATH_CACHE }}/github_v1_16_1.tar github_v1_16:latest
    71            docker save --output ${{ env.PATH_CACHE }}/github_v1_17_1.tar github_v1_17:latest
    72            docker save --output ${{ env.PATH_CACHE }}/github_v1_18_1.tar github_v1_18:latest
    73            docker save --output ${{ env.PATH_CACHE }}/github_v1_19_1.tar github_v1_19:latest
    74            docker save --output ${{ env.PATH_CACHE }}/github_latest_1.tar github_latest:latest
    75  
    76        - name: Run tests on Go 1.16
    77          run: docker-compose --file ./.github/docker-compose.yml run v1_16
    78        - name: Run tests on Go 1.17
    79          run: docker-compose --file ./.github/docker-compose.yml run v1_17
    80        - name: Run tests on Go 1.18
    81          run: docker-compose --file ./.github/docker-compose.yml run v1_18
    82        - name: Run tests on Go 1.19
    83          run: docker-compose --file ./.github/docker-compose.yml run v1_19
    84        - name: Run tests on latest Go
    85          run: docker-compose --file ./.github/docker-compose.yml run latest