diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..35bd0365 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,52 @@ +name: ci +env: + EARTHLY_TOKEN: ${{ secrets.EARTHLY_TOKEN }} + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} + FORCE_COLOR: 1 + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: earthly/actions-setup@v1 + with: + version: v0.8.14 + - uses: actions/checkout@v2 + - name: Docker Login + run: echo "$DOCKERHUB_TOKEN" | docker login --username "$DOCKERHUB_USERNAME" --password-stdin + - name: Run build + run: earthly --ci +ci + + test: + runs-on: ubuntu-latest + steps: + - uses: earthly/actions-setup@v1 + with: + version: v0.8.14 + - uses: actions/checkout@v2 + - name: Docker Login + run: echo "$DOCKERHUB_TOKEN" | docker login --username "$DOCKERHUB_USERNAME" --password-stdin + - name: Run build + run: earthly -P --ci +test + + build-prod: + runs-on: ubuntu-latest + needs: test + if: success() && github.ref == 'refs/heads/main' + steps: + - uses: earthly/actions-setup@v1 + with: + version: v0.8.14 + - uses: actions/checkout@v2 + - name: Docker Login + run: echo "$DOCKERHUB_TOKEN" | docker login --username "$DOCKERHUB_USERNAME" --password-stdin + - name: Run build + run: earthly -P --ci --push +docker + diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 6d6b5e2b..00000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: docker - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - runs-on: ubuntu-latest - env: - GHCR_USERNAME: ${{ github.actor }} - GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }} - FORCE_COLOR: 1 - steps: - - uses: actions/checkout@v3 - - name: Put back the git branch into git (Earthly uses it for tagging) - run: | - branch="" - if [ -n "$GITHUB_HEAD_REF" ]; then - branch="$GITHUB_HEAD_REF" - else - branch="${GITHUB_REF##*/}" - fi - git checkout -b "$branch" || true - - name: Docker Login - run: docker login https://ghcr.io --username "$GHCR_USERNAME" --password "$GHCR_TOKEN" - - name: Download latest earthly - run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" - - name: Earthly version - run: earthly --version - - name: Run test and build - run: earthly -P --platform linux/amd64 --build-arg GITHUB_REPO=${{ github.repository }} --push +docker diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml deleted file mode 100644 index e7c87cf4..00000000 --- a/.github/workflows/lint.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: lint - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - runs-on: ubuntu-latest - env: - GHCR_USERNAME: ${{ github.actor }} - GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }} - FORCE_COLOR: 1 - steps: - - uses: actions/checkout@v3 - - name: Put back the git branch into git (Earthly uses it for tagging) - run: | - branch="" - if [ -n "$GITHUB_HEAD_REF" ]; then - branch="$GITHUB_HEAD_REF" - else - branch="${GITHUB_REF##*/}" - fi - git checkout -b "$branch" || true - - name: Docker Login - run: docker login https://ghcr.io --username "$GHCR_USERNAME" --password "$GHCR_TOKEN" - - name: Download latest earthly - run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" - - name: Earthly version - run: earthly --version - - name: Run lint - run: earthly -P --build-arg GITHUB_REPO=${{ github.repository }} +ci diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 6c4b0022..00000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: test - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - runs-on: ubuntu-latest - env: - GHCR_USERNAME: ${{ github.actor }} - GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }} - FORCE_COLOR: 1 - steps: - - uses: actions/checkout@v3 - - name: Put back the git branch into git (Earthly uses it for tagging) - run: | - branch="" - if [ -n "$GITHUB_HEAD_REF" ]; then - branch="$GITHUB_HEAD_REF" - else - branch="${GITHUB_REF##*/}" - fi - git checkout -b "$branch" || true - - name: Docker Login - run: docker login https://ghcr.io --username "$GHCR_USERNAME" --password "$GHCR_TOKEN" - - name: Download latest earthly - run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'" - - name: Earthly version - run: earthly --version - - name: Run tests - run: earthly -P --build-arg GITHUB_REPO=${{ github.repository }} +test diff --git a/README.md b/README.md index 03f4ed3e..46472aa3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # PEA Pescarte -[![lint](https://github.com/peapescarte/pescarte-api/actions/workflows/lint.yml/badge.svg)](https://github.com/peapescarte/pescarte-api/actions/workflows/lint.yml) -[![test](https://github.com/peapescarte/pescarte-api/actions/workflows/test.yml/badge.svg)](https://github.com/peapescarte/pescarte-api/actions/workflows/test.yml) +[![ci](https://github.com/peapescarte/pescarte-plataforma/actions/workflows/ci.yml/badge.svg)](https://github.com/peapescarte/pescarte-plataforma/actions/workflows/ci.yml) ------------------------------------------------------------------------