From f18302f54193c5f60a6b9d8419b81200bb012c0b Mon Sep 17 00:00:00 2001 From: Graham Steffaniak <42989099+gtsteffaniak@users.noreply.github.com> Date: Fri, 15 Sep 2023 18:56:30 -0500 Subject: [PATCH] Update workflows (#32) Co-authored-by: Graham Steffaniak --- .github/workflows/main.yaml | 31 +++++++++-------- .github/workflows/pr-merge.yaml | 59 +++++++++++++++++++++++++++++++ .github/workflows/release.yaml | 61 +++++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/pr-merge.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 80ea3969..67f05a87 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -4,11 +4,6 @@ on: push: branches: - 'main' - - 'v\d+.\d+.\d+' - pull_request: - branches: - - 'main' - - 'v\d+.\d+.\d+' jobs: test: runs-on: ubuntu-latest @@ -26,20 +21,26 @@ jobs: with: go-version: 1.21.1 - run: cd backend && go fmt ./... - push_to_registry: + push_latest_to_registry: needs: [lint, test] - name: Push Docker image to Docker Hub + name: Push latest runs-on: ubuntu-latest - if: contains(github.ref, 'main') || startsWith(github.ref,'v0.') + if: branch-name.outputs.is_default == 'true' steps: - - name: Check out the repo + - name: Checkout uses: actions/checkout@v4 - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + uses: docker/setup-qemu-action@v3.0.0 - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - name: Log in to Docker Hub - uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + uses: docker/setup-buildx-action@v3.0.0 + # Workaround to fix error: + # failed to push: failed to copy: io: read/write on closed pipe + # See https://github.com/docker/build-push-action/issues/761 + with: + driver-opts: | + image=moby/buildkit:v0.10.6 + - name: Login to Docker Hub + uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} @@ -55,5 +56,5 @@ jobs: platforms: linux/amd64,linux/arm64,linux/arm/v7 file: ./Dockerfile push: true - tags: ${{ contains(github.ref, 'main') && 'latest' || steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + tags: 'gtstef/filebrowser:latest' + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/pr-merge.yaml b/.github/workflows/pr-merge.yaml new file mode 100644 index 00000000..dca6c543 --- /dev/null +++ b/.github/workflows/pr-merge.yaml @@ -0,0 +1,59 @@ +name: pr-merge + +on: + pull_request: + branches: + - 'main' + - 'v\d+.\d+.\d+' +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: 1.21.1 + - run: cd backend && go test -race -v ./... + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: 1.21.1 + - run: cd backend && go fmt ./... + push_pr_to_registry: + needs: [lint, test] + name: Push PR + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.0.0 + # Workaround to fix error: + # failed to push: failed to copy: io: read/write on closed pipe + # See https://github.com/docker/build-push-action/issues/761 + with: + driver-opts: | + image=moby/buildkit:v0.10.6 + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: gtstef/filebrowser + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 00000000..175e205c --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,61 @@ +name: release + +on: + push: + branches: + - 'v\d+.\d+.\d+' +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: 1.21.1 + - run: cd backend && go test -race -v ./... + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: 1.21.1 + - run: cd backend && go fmt ./... + push_release_to_registry: + needs: [lint, test] + name: Push release + runs-on: ubuntu-latest + if: ${{ github.event_name == 'release' }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3.0.0 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3.0.0 + # Workaround to fix error: + # failed to push: failed to copy: io: read/write on closed pipe + # See https://github.com/docker/build-push-action/issues/761 + with: + driver-opts: | + image=moby/buildkit:v0.10.6 + - name: Login to Docker Hub + # Only push to Docker Hub when making a release + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: gtstef/filebrowser + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + platforms: linux/amd64,linux/arm64,linux/arm/v7 + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file