Home > Article > Development Tools > how to create github actions workflow
How do I set up a workflow that triggers on a specific event?
To set up a workflow that triggers on a specific event, you need to define an event in the .github/workflows
directory. The event can be a push, pull request, or other specific event. For example, the following workflow is triggered when a push is made to the main branch:
<code class="yaml">name: Push to main on: push: branches: [ main ]</code>
How can I use GitHub Actions to automate a workflow in my repository?
GitHub Actions can be used to automate a wide variety of workflows in your repository. Some common examples include:
To automate a workflow, you need to create a workflow file in the .github/workflows
directory. The workflow file defines the steps that will be executed when the workflow is triggered. For example, the following workflow builds and tests a Node.js application:
<code class="yaml">name: Build and test on: [push, pull_request] jobs: build-and-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: 16 - run: npm install - run: npm test</code>
Here are some best practices for creating GitHub Actions workflows:
The above is the detailed content of how to create github actions workflow. For more information, please follow other related articles on the PHP Chinese website!