From d9697e7d43506b7167946c211a1a13547a36183c Mon Sep 17 00:00:00 2001 From: lens0021 Date: Fri, 16 Apr 2021 21:53:15 +0900 Subject: [PATCH] actions: Use docker actions --- .github/workflows/main.yaml | 38 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 1fd05f3..fd39c14 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -9,23 +9,29 @@ env: jobs: docker_image_job: runs-on: ubuntu-18.04 - if: github.event_name == 'push' steps: - - uses: actions/checkout@v2 + # don't need to use the actions/checkout when working with setup-buildx-action - - name: Build image - run: docker build . --tag $IMAGE_NAME + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 - - name: Log into GitHub Container Registry - run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u femiwiki-bot --password-stdin + - name: Login to GitHub Container Registry + if: github.repository_owner == 'femiwiki' + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: femiwiki-bot + password: ${{ secrets.GITHUB_TOKEN }} - - name: Push image to GitHub Container Registry - run: | - IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME - VERSION=$(date +%Y-%m-%dT%H-%M)-$(echo ${{ github.sha }} | cut -c1-8) - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker tag $IMAGE_NAME $IMAGE_ID:latest - docker push $IMAGE_ID:$VERSION - docker push $IMAGE_ID:latest + - id: version + run: echo "::set-output name=version::$(date +%Y-%m-%dT%H-%M)-$(echo ${{ github.sha }} | cut -c1-8)" + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + cache-from: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest + with: + push: ${{ github.repository_owner == 'femiwiki' }} + tags: | + ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }} + ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest