master.yml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. name: Tag, Release and Docker Build & Push
  2. #on:
  3. # push:
  4. # branches:
  5. # - master
  6. on:
  7. workflow_dispatch:
  8. permissions:
  9. packages: write
  10. contents: write
  11. env:
  12. REPOSITORY: ${{ github.repository }}
  13. jobs:
  14. setup:
  15. name: Setup
  16. runs-on: ubuntu-latest
  17. outputs:
  18. repository: ${{ steps.vars.outputs.GITHUB_PROJECT_NAME }}
  19. steps:
  20. - name: Set lowercase repository
  21. id: vars
  22. run: echo "GITHUB_PROJECT_NAME=$(echo '${{ env.REPOSITORY }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT
  23. build:
  24. name: Build Images
  25. runs-on: ubuntu-latest
  26. needs: setup
  27. steps:
  28. - name: Checkout
  29. uses: actions/checkout@v4
  30. - name: Setup Taskfile
  31. uses: pnorton5432/setup-task@v1
  32. with:
  33. task-version: 3.40.1
  34. - name: Build Docker images
  35. run: task actions:build-${{ github.sha }}
  36. env:
  37. GITHUB_PROJECT_NAME: ${{ needs.setup.outputs.repository }}
  38. - name: Upload Docker images artifacts
  39. uses: actions/upload-artifact@v4
  40. with:
  41. name: docker-images-${{ github.sha }}
  42. path: ./${{ github.sha }}
  43. retention-days: 1
  44. overwrite: true
  45. tag:
  46. name: Create Tag
  47. runs-on: ubuntu-latest
  48. needs: build
  49. outputs:
  50. tag: ${{ steps.tag.outputs.new_tag }}
  51. changelog: ${{ steps.tag.outputs.changelog }}
  52. steps:
  53. - uses: actions/checkout@v4
  54. - name: Bump version and push tag
  55. id: tag
  56. uses: mathieudutour/github-tag-action@v6.2
  57. with:
  58. github_token: ${{ secrets.GITHUB_TOKEN }}
  59. release:
  60. name: Publish Release
  61. runs-on: ubuntu-latest
  62. needs: tag
  63. outputs:
  64. tag: ${{ needs.tag.outputs.tag }}
  65. steps:
  66. - uses: actions/checkout@v4
  67. - name: Create a GitHub release
  68. uses: ncipollo/release-action@v1
  69. with:
  70. tag: ${{ needs.tag.outputs.tag }}
  71. name: Release ${{ needs.tag.outputs.tag }}
  72. body: ${{ needs.tag.outputs.changelog }}
  73. push:
  74. name: Push Images
  75. runs-on: ubuntu-latest
  76. needs:
  77. - setup
  78. - release
  79. outputs:
  80. tag: ${{ needs.release.outputs.tag }}
  81. steps:
  82. - name: Checkout
  83. uses: actions/checkout@v4
  84. - name: Log in to GitHub Container Registry
  85. uses: docker/login-action@v2
  86. with:
  87. registry: ghcr.io
  88. username: ${{ github.actor }}
  89. password: ${{ secrets.GITHUB_TOKEN }}
  90. - name: Setup Taskfile
  91. uses: pnorton5432/setup-task@v1
  92. with:
  93. task-version: 3.40.1
  94. - name: Download Docker images artifacts
  95. uses: actions/download-artifact@v5
  96. with:
  97. name: docker-images-${{ github.sha }}
  98. path: ./${{ github.sha }}
  99. - name: Load Docker images
  100. run: task actions:load-${{ github.sha }}
  101. env:
  102. GITHUB_PROJECT_NAME: ${{ needs.setup.outputs.repository }}
  103. - name: Tag Docker images
  104. run: task actions:tag-${{ needs.release.outputs.tag }}
  105. env:
  106. GITHUB_PROJECT_NAME: ${{ needs.setup.outputs.repository }}
  107. - name: Push Docker images
  108. run: task actions:push-${{ needs.release.outputs.tag }}
  109. env:
  110. GITHUB_PROJECT_NAME: ${{ needs.setup.outputs.repository }}
  111. deploy:
  112. name: Deploy In Production
  113. runs-on: ubuntu-latest
  114. needs:
  115. - push
  116. steps:
  117. - uses: appleboy/ssh-action@v1.2.0
  118. with:
  119. host: ${{ secrets.HOST }}
  120. username: ${{ secrets.USERNAME }}
  121. key: ${{ secrets.KEY }}
  122. port: 22
  123. script: |
  124. # cd /opt/production
  125. task update-tag-${{ needs.push.outputs.tag }}
  126. task deploy