From b22ad5442575e44ae0eb0d2fdfc80c323edaaa89 Mon Sep 17 00:00:00 2001 From: Chad Fawcett Date: Thu, 7 Mar 2024 14:10:46 -0800 Subject: [PATCH] Update Actions examples in "Contexts" (#49585) --- .../actions/learn-github-actions/contexts.md | 47 +++++++------------ .../actions/github_token-input-example.md | 18 +++---- 2 files changed, 27 insertions(+), 38 deletions(-) diff --git a/content/actions/learn-github-actions/contexts.md b/content/actions/learn-github-actions/contexts.md index cbc97ada82..b70280fde0 100644 --- a/content/actions/learn-github-actions/contexts.md +++ b/content/actions/learn-github-actions/contexts.md @@ -66,7 +66,7 @@ The following example demonstrates how these different types of variables can be {% raw %} -```yaml +```yaml copy name: CI on: push jobs: @@ -286,17 +286,15 @@ jobs: normal_ci: runs-on: ubuntu-latest steps: - - uses: {% data reusables.actions.action-checkout %} - name: Run normal CI - run: ./run-tests + run: echo "Running normal CI" pull_request_ci: runs-on: ubuntu-latest if: {% raw %}${{ github.event_name == 'pull_request' }}{% endraw %} steps: - - uses: {% data reusables.actions.action-checkout %} - name: Run PR CI - run: ./run-additional-pr-ci + run: echo "Running PR only CI" ``` ## `env` context @@ -441,9 +439,8 @@ jobs: - 5432 steps: - - uses: {% data reusables.actions.action-checkout %} - run: pg_isready -h localhost -p {% raw %}${{ job.services.postgres.ports[5432] }}{% endraw %} - - run: ./run-tests + - run: echo "Run tests against Postgres" ``` ## `jobs` context @@ -562,8 +559,6 @@ jobs: randomly-failing-job: runs-on: ubuntu-latest steps: - - id: checkout - uses: {% data reusables.actions.action-checkout %} - name: Generate 0 or 1 id: generate_number {%- ifversion actions-save-state-set-output-envs %} @@ -629,7 +624,8 @@ jobs: - name: Build with logs run: | mkdir {% raw %}${{ runner.temp }}{% endraw %}/build_logs - ./build.sh --log-path {% raw %}${{ runner.temp }}{% endraw %}/build_logs + echo "Logs from building" > {% raw %}${{ runner.temp }}{% endraw %}/build_logs/build.logs + exit 1 - name: Upload logs on fail if: {% raw %}${{ failure() }}{% endraw %} uses: {% data reusables.actions.action-upload-artifact %} @@ -698,7 +694,7 @@ The following example contents of the `strategy` context is from a matrix with f This example workflow uses the `strategy.job-index` property to set a unique name for a log file for each job in a matrix. ```yaml copy -name: Test matrix +name: Test strategy on: push jobs: @@ -709,8 +705,7 @@ jobs: test-group: [1, 2] node: [14, 16] steps: - - uses: {% data reusables.actions.action-checkout %} - - run: npm test > test-job-{% raw %}${{ strategy.job-index }}{% endraw %}.txt + - run: echo "Mock test logs" > test-job-{% raw %}${{ strategy.job-index }}{% endraw %}.txt - name: Upload logs uses: {% data reusables.actions.action-upload-artifact %} with: @@ -756,14 +751,11 @@ jobs: os: [ubuntu-latest, windows-latest] node: [14, 16] steps: - - uses: {% data reusables.actions.action-checkout %} - uses: {% data reusables.actions.action-setup-node %} with: node-version: {% raw %}${{ matrix.node }}{% endraw %} - - name: Install dependencies - run: npm ci - - name: Run tests - run: npm test + - name: Output node version + run: node --version ``` ## `needs` context @@ -787,7 +779,7 @@ The following example contents of the `needs` context shows information for two "build": { "result": "success", "outputs": { - "build_id": "ABC123" + "build_id": "123456" } }, "deploy": { @@ -811,29 +803,24 @@ jobs: outputs: build_id: {% raw %}${{ steps.build_step.outputs.build_id }}{% endraw %} steps: - - uses: {% data reusables.actions.action-checkout %} - name: Build id: build_step - run: | - ./build {%- ifversion actions-save-state-set-output-envs %} - echo "build_id=$BUILD_ID" >> $GITHUB_OUTPUT + run: echo "build_id=$RANDOM" >> $GITHUB_OUTPUT {%- else %} - echo "::set-output name=build_id::$BUILD_ID" + run: echo "::set-output name=build_id::$RANDOM" {%- endif %} deploy: needs: build runs-on: ubuntu-latest steps: - - uses: {% data reusables.actions.action-checkout %} - - run: ./deploy --build {% raw %}${{ needs.build.outputs.build_id }}{% endraw %} + - run: echo "Deploying build {% raw %}${{ needs.build.outputs.build_id }}{% endraw %}" debug: needs: [build, deploy] runs-on: ubuntu-latest if: {% raw %}${{ failure() }}{% endraw %} steps: - - uses: {% data reusables.actions.action-checkout %} - - run: ./debug + - run: echo "Failed to build and deploy" ``` ## `inputs` context @@ -886,7 +873,7 @@ jobs: if: ${{ inputs.perform_deploy }} steps: - name: Deploy build to target - run: deploy --build ${{ inputs.build_id }} --target ${{ inputs.deploy_target }} + run: echo "Deploying build:${{ inputs.build_id }} to target:${{ inputs.deploy_target }}" ``` {% endraw %} @@ -919,7 +906,7 @@ jobs: if: ${{ inputs.perform_deploy }} steps: - name: Deploy build to target - run: deploy --build ${{ inputs.build_id }} --target ${{ inputs.deploy_target }} + run: echo "Deploying build:${{ inputs.build_id }} to target:${{ inputs.deploy_target }}" ``` {% endraw %} diff --git a/data/reusables/actions/github_token-input-example.md b/data/reusables/actions/github_token-input-example.md index 0cf47234bb..eaa824a10b 100644 --- a/data/reusables/actions/github_token-input-example.md +++ b/data/reusables/actions/github_token-input-example.md @@ -1,17 +1,19 @@ -This example workflow uses the [labeler action](https://github.com/actions/labeler), which requires the `GITHUB_TOKEN` as the value for the `repo-token` input parameter: +This example workflow uses the [GitHub CLI](/actions/using-workflows/using-github-cli-in-workflows), which requires the `GITHUB_TOKEN` as the value for the `GH_TOKEN` input parameter: ```yaml copy -name: Pull request labeler -on: [ pull_request_target ] +name: Open new issue +on: workflow_dispatch jobs: - triage: + open-issue: runs-on: ubuntu-latest permissions: contents: read - pull-requests: write + issues: write steps: - - uses: {% data reusables.actions.action-labeler %} - with: - repo-token: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %} + - run: | + gh issue --repo {% raw %}${{ github.repository }}{% endraw %} \ + create --title "Issue title" --body "Issue body" + env: + GH_TOKEN: {% raw %}${{ secrets.GITHUB_TOKEN }}{% endraw %} ```