Try   HackMD

Github Actions

理論

以前更新程式到伺服器

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

為了保持一致改用 git, github (很多人一起寫時,不用git很容易出錯)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

讓他變自動

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

實戰

name: 'Github Actions'

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    if: "!contains(github.event.head_commit.message, '[skip ci]')"

    steps:
    - name: Checkout project
      uses: actions/checkout@v3

    - name: Specify node version
    - uses: actions/setup-node@v3
      with:
        node-version: '16.x'
        registry-url: 'https://registry.npmjs.org'

    - name: Install node_modules
      run:
        npm ci

    - name: Lint
      run:
        npm run lint

    - name: Test
      run:
        npm run test

  deploy:
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'
    steps:
      - name: Set up the private key
        uses: webfactory/ssh-agent@v0.7.0
        with:
          ssh-private-key: ${{ secrets.SSH_KEY }}

      - name: Set known_hosts
        run: echo "${{ secrets.KNOWN_HOSTS }}" >> ~/.ssh/known_hosts

      - name: Connect to the production environment
        run: ssh ${{ secrets.USER_HOST }} '
          cd /srv/node/my_project
          && git pull
          && npm ci
          '

參考資料

https://stackoverflow.com/questions/67516571/github-action-triggered-by-success-of-a-different-action
https://stackoverflow.com/questions/63148639/create-dependencies-between-jobs-in-github-actions
https://ubuntudroid.medium.com/labeling-github-auto-merge-pull-requests-d5a86f62280a