Skip to content

Commit

Permalink
Only push to DockerHub when commit on master branch (#4)
Browse files Browse the repository at this point in the history
* Only push to Dockerhub on master

* Supress user nullable warning

* Use on pr condition instead
  • Loading branch information
84634E1A607A authored Jul 20, 2024
1 parent 32a7b05 commit a580650
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
name: docker-build
on: [push]
name: Docker Build Image

on:
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Docker Login
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and Push

- name: Build Image
uses: docker/[email protected]
with:
file: dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/thuinfo-web:latest
push: true
push: false
25 changes: 25 additions & 0 deletions .github/workflows/docker-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Docker Build and Push Image to DockerHub

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Docker Login
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build Image and Push to DockerHub
uses: docker/[email protected]
with:
file: dockerfile
tags: ${{ secrets.DOCKERHUB_USERNAME }}/thuinfo-web:latest
push: true
4 changes: 2 additions & 2 deletions ThuInfoWeb/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ public async Task<IActionResult> CreateAnnounce(AnnounceViewModel vm)
if (vm.Title is null || vm.Content is null) return BadRequest("标题或内容为空");
vm.VisibleNotAfter ??= "9.9.9";
vm.VisibleExact ??= "";
var user = HttpContext.User.Identity?.Name;
var user = HttpContext.User.Identity!.Name!;
var a = new Announce
{
Title = vm.Title,
Content = vm.Content,
Author = user ?? "",
Author = user,
CreatedTime = DateTime.Now,
IsActive = vm.IsActive,
VisibleNotAfter = vm.VisibleNotAfter,
Expand Down

0 comments on commit a580650

Please sign in to comment.