diff --git a/.github/workflows/auto-release.yml b/.github/workflows/auto-release.yml index 6a2d30b7..ccc27be7 100644 --- a/.github/workflows/auto-release.yml +++ b/.github/workflows/auto-release.yml @@ -3,17 +3,17 @@ name: auto-release on: push: branches: - - master + - master jobs: semver: runs-on: ubuntu-latest steps: - # Drafts your next Release notes as Pull Requests are merged into "master" - - uses: release-drafter/release-drafter@v5 - with: - publish: true - prerelease: false - config-name: auto-release.yml - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Drafts your next Release notes as Pull Requests are merged into "master" + - uses: release-drafter/release-drafter@v5 + with: + publish: true + prerelease: false + config-name: auto-release.yml + env: + GITHUB_TOKEN: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }} diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml deleted file mode 100644 index 4482f848..00000000 --- a/.github/workflows/build-and-push.yml +++ /dev/null @@ -1,25 +0,0 @@ -name: "docker" -on: - push: - branches: - - master - pull_request: - types: [opened, synchronize, reopened] - release: - types: - - created -jobs: - build-and-push: - runs-on: ubuntu-latest - steps: - - name: "Checkout source code at current commit" - uses: actions/checkout@v2 - - name: "Build and push docker image to DockerHub" - uses: docker/build-push-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - repository: ${{ github.repository }} - registry: registry-1.docker.io - tag_with_ref: true - tag_with_sha: true diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..1190447e --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,44 @@ +name: "docker" +on: + pull_request: + types: [opened, synchronize, reopened] + release: + types: + - created +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: "Checkout source code at current commit" + uses: actions/checkout@v2 + - name: Prepare tags for Docker image + if: (github.event_name == 'release' && github.event.action == 'created') || github.event.pull_request.head.repo.full_name == github.repository + id: prepare + run: | + TAGS=${{ github.repository }}:sha-${GITHUB_SHA:0:7} + if [[ $GITHUB_REF == refs/tags/* ]]; then + VERSION=${GITHUB_REF#refs/tags/} + elif [[ $GITHUB_REF == refs/pull/* ]]; then + VERSION=pr-${{ github.event.pull_request.number }}-merge + fi + if [[ -n $VERSION ]]; then + TAGS="$TAGS,${{ github.repository }}:${VERSION}" + fi + if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + TAGS="$TAGS,${{ github.repository }}:latest" + fi + echo ::set-output name=tags::${TAGS} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub + if: (github.event_name == 'release' && github.event.action == 'created') || github.event.pull_request.head.repo.full_name == github.repository + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: "Build and push docker image to DockerHub" + id: docker_build + uses: docker/build-push-action@v2 + with: + push: ${{ (github.event_name == 'release' && github.event.action == 'created') || github.event.pull_request.head.repo.full_name == github.repository }} + tags: ${{ steps.prepare.outputs.tags }} diff --git a/templates/.github/workflows/auto-release.yml b/templates/.github/workflows/auto-release.yml index e21fbfe4..ccc27be7 100644 --- a/templates/.github/workflows/auto-release.yml +++ b/templates/.github/workflows/auto-release.yml @@ -3,17 +3,17 @@ name: auto-release on: push: branches: - - master + - master jobs: semver: runs-on: ubuntu-latest steps: - # Drafts your next Release notes as Pull Requests are merged into "master" - - uses: release-drafter/release-drafter@v5 - with: - publish: true - prerelease: false - config-name: auto-release.yml - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # Drafts your next Release notes as Pull Requests are merged into "master" + - uses: release-drafter/release-drafter@v5 + with: + publish: true + prerelease: false + config-name: auto-release.yml + env: + GITHUB_TOKEN: ${{ secrets.PUBLIC_REPO_ACCESS_TOKEN }}