diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml deleted file mode 100644 index d0ba0c2..0000000 --- a/.github/workflows/build-and-deploy.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: 构建和部署 - -on: - push: - branches: - - main - -permissions: - contents: write - -jobs: - build-and-deploy: - runs-on: ubuntu-latest - - steps: - - name: 检出仓库 - uses: actions/checkout@v2 - with: - fetch-depth: 0 # 需要获取所有历史记录以创建标签 - - - name: 设置Node.js - uses: actions/setup-node@v2 - with: - node-version: "19" - - - name: 下载pnpm - run: npm install -g pnpm - - - name: 安装依赖 - run: pnpm install - - - name: 构建项目 - run: pnpm run build - - - name: 设置Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: 登录Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: 获取并递增版本号 - id: version - run: | - NEW_VERSION=$(echo $(cat VERSION) | awk -F. '{printf("%d.%d.%d\n",$1,$2,$3+1)}') - echo "::set-output name=new-version::$NEW_VERSION" - - - name: 更新版本号并推送更改 - env: - GIT_TOKEN: ${{ secrets.GIT_TOKEN }} - run: | - echo ${{ steps.version.outputs.new-version }} > VERSION - git config --global user.name 'wu529778790' - git config --global user.email '529778790@qq.com' - git remote set-url origin https://${GIT_TOKEN}@github.com/${{ github.repository }} - git add VERSION - git commit -m "chore: bump version to ${{ steps.version.outputs.new-version }}" - git push - git push origin --tags - - - name: 构建并推送Docker镜像 - uses: docker/build-push-action@v2 - with: - context: . - push: true - tags: wu529778790/wallpaper.shenzjd.com:${{ steps.version.outputs.new-version }} diff --git a/.github/workflows/deploy-to-docker.yaml b/.github/workflows/deploy-to-docker.yaml new file mode 100644 index 0000000..a1786f4 --- /dev/null +++ b/.github/workflows/deploy-to-docker.yaml @@ -0,0 +1,66 @@ +name: Deploy to Docker + +on: + push: + branches: + - main + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v2 + with: + node-version: "19" + + - name: Install Pnpm + run: npm install pnpm -g + + - name: Install dependencies + run: pnpm install + + - name: Build project + run: pnpm run build + + - name: Update version and commit + run: | + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + npm version patch -m "chore(release): v%s [skip ci]" + if: ${{ always() }} + + - name: Set Docker Buildx + uses: docker/setup-buildx-action@v1 + if: ${{ always() }} + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + if: ${{ always() }} + + - name: Get version + id: version + run: echo ::set-output name=new-version::$(npm version patch) + if: ${{ always() }} + + - name: Build and push docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: | + wu529778790/wallpaper.shenzjd.com:${{ steps.version.outputs.new-version }} + wu529778790/wallpaper.shenzjd.com:latest + if: ${{ always() }} + + - name: Push Git changes + run: | + git push + if: ${{ always() }}