From 93abdf6497ac57fa4ef77b0a3d9e15672abec7ac Mon Sep 17 00:00:00 2001 From: iiTzArcur Date: Thu, 9 Nov 2023 15:42:38 +0100 Subject: [PATCH] Update main.yml --- .github/workflows/main.yml | 91 +++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 46 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f3492e6..fdf906c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,55 +1,54 @@ +# This is a basic workflow to help you get started with Actions -on: - workflow_dispatch: - pull_request: - # Publish `main` as Docker `latest` image. - branches: - - master - - # Publish `v1.2.3` tags as releases. - tags: - - v* +name: CI - # Run tests for any PRs. +# Controls when the workflow will run +on: + # Triggers the workflow on push or pull request events but only for the main branch push: + branches: [ main ] + pull_request: + branches: [ main ] -env: - # Image name - IMAGE_NAME: marne-bot + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: +# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ - push: - + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on runs-on: ubuntu-latest - if: github.event_name == 'push' + # Steps represent a sequence of tasks that will be executed as part of the job steps: - - uses: actions/checkout@v2 -# if credentials github needed -# - uses: fusion-engineering/setup-git-credentials@v2 -# with: -# credentials: ${{secrets.GIT_CREDENTIALS}} - - - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME --build-arg github_token=${{ secrets.GIT_CREDENTIALS }} - - - name: Log into registry - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin - - - name: Push image - run: | - IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - # Strip git ref prefix from version - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - # Strip "v" prefix from tag name - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - # Use Docker `latest` tag convention - [ "$VERSION" == "main" ] && VERSION=latest - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION + - name: Checkout + uses: actions/checkout@v2 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to Registry + uses: docker/login-action@v1 + with: + # registry: docker.pkg.github.com + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GIT_CREDENTIALS }} + + - name: Cache Docker layers + uses: actions/cache@v2 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: ${{ runner.os }}-buildx- + + - uses: docker/build-push-action@v2 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: ghcr.io/${{ github.repository }}/marne-bot:latest