From 374f426961e1682c82d08267050282dcd05e3600 Mon Sep 17 00:00:00 2001 From: projectmoon Date: Mon, 31 Aug 2020 21:35:19 +0000 Subject: [PATCH] Switch to docker hub because github packages is useless. --- .github/workflows/dicebot-ci.yml | 58 +++++++++++++++----------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/.github/workflows/dicebot-ci.yml b/.github/workflows/dicebot-ci.yml index 8f7bdff..e8206c8 100644 --- a/.github/workflows/dicebot-ci.yml +++ b/.github/workflows/dicebot-ci.yml @@ -2,7 +2,6 @@ name: Dicebot CI on: push: - # Publish `master` as Docker `latest` image. branches: - master @@ -18,8 +17,6 @@ env: CARGO_TERM_COLOR: always jobs: - # Run tests. - # See also https://docs.docker.com/docker-hub/builds/automated-testing/ build_and_test: runs-on: ubuntu-latest steps: @@ -29,42 +26,41 @@ jobs: - name: Run tests run: cargo test --verbose - # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ - docker_push: - # Ensure test job passes before pushing image. + docker_push_latest: needs: build_and_test runs-on: ubuntu-latest if: github.event_name == 'push' steps: - - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v2 - - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME + - name: Build and push Docker images + uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: myorg/myrepository + tags: latest + push: ${{ startsWith(github.ref, 'master') }} - - name: Log into registry - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin + docker_push_tag: + needs: build_and_test - - name: Push image - run: | - IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME + runs-on: ubuntu-latest + if: github.event_name == 'push' - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + steps: + - name: Checkout code + uses: actions/checkout@v2 - # 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" == "master" ] && VERSION=latest - - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION + - name: Build and push Docker images + uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: myorg/myrepository + tags: latest + tag_with_ref: true + push: ${{ startsWith(github.ref, 'refs/tags/') }}