Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preflight workflow test #49

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ concurrency:
permissions: {}

jobs:

preflight:
permissions:
pull-requests: read
uses: ./.github/workflows/reusable-preflight.yml

# temporary disabled because currently doesn't work in merge queue
# changes:
# permissions:
Expand Down
112 changes: 112 additions & 0 deletions .github/workflows/reusable-preflight.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Preflight

on:
workflow_call:
# Map the workflow outputs to job outputs
outputs:
changes_rust:
value: ${{ jobs.changes.outputs.changes_rust }}
changes_currentWorkflow:
value: ${{ jobs.changes.outputs.changes_currentWorkflow }}

IMAGE:
value: ${{ jobs.changes.outputs.IMAGE }}
description: "CI image"
RUNNER:
value: ${{ jobs.changes.outputs.RUNNER }}
description: |
Runner name.
By default we use spot machines that can be terminated at any time.
Merge queues use persistent runners to avoid kicking off from queue when the runner is terminated.
SOURCE_REF_NAME:
value: ${{ jobs.changes.outputs.SOURCE_REF_NAME }}
description: "Name of the current branch for `push` or source branch for `pull_request`"
COMMIT_SHA:
value: ${{ jobs.changes.outputs.COMMIT_SHA }}
description: "Sha of the current commit for `push` or head of the source branch for `pull_request`"

jobs:
changes:
runs-on: ubuntu-latest
outputs:
changes_rust: ${{ steps.set_changes.outputs.rust_any_changed || steps.set_changes.outputs.currentWorkflow_any_changed }}
changes_currentWorkflow: ${{ steps.set_changes.outputs.currentWorkflow_any_changed }}

IMAGE: ${{ steps.set_image.outputs.IMAGE }}
RUNNER: ${{ steps.set_runner.outputs.RUNNER }}

SOURCE_REF_NAME: ${{ steps.set_vars.outputs.SOURCE_REF_NAME }}
COMMIT_SHA: ${{ steps.set_vars.outputs.COMMIT_SHA }}


steps:

- uses: actions/checkout@v4

#
# Set changes
#
- id: current_file
shell: bash
run: |
echo "currentWorkflowFile=$(echo ${{ github.workflow_ref }} | sed -nE "s/.*(\.github\/workflows\/[a-zA-Z0-9_-]*\.y[a]?ml)@refs.*/\1/p")" >> $GITHUB_OUTPUT
echo "currentActionDir=$(echo ${{ github.action_path }} | sed -nE "s/.*(\.github\/actions\/[a-zA-Z0-9_-]*)/\1/p")" >> $GITHUB_OUTPUT

- name: Set changes
id: set_changes
uses: tj-actions/changed-files@v45
with:
files_yaml: |
rust:
- '**/*'
- '!.github/**/*'
- '!prdoc/**/*'
- '!docs/**/*'
currentWorkflow:
- '${{ steps.current_file.outputs.currentWorkflowFile }}'
- '.github/workflows/reusable-preflight.yml'

#
# Set image
#
- name: Set image
id: set_image
shell: bash
run: cat .github/env >> $GITHUB_OUTPUT

#
# Set runner
#
# By default we use spot machines that can be terminated at any time.
# Merge queues use persistent runners to avoid kicking off from queue when the runner is terminated.
#
- id: set_runner
shell: bash
run: |
# Run merge queues on persistent runners
if [[ $GITHUB_REF_NAME == *"gh-readonly-queue"* ]]; then
echo "RUNNER=arc-runners-polkadot-sdk-beefy-persistent" >> $GITHUB_OUTPUT
else
echo "RUNNER=arc-runners-polkadot-sdk-beefy" >> $GITHUB_OUTPUT
fi

#
# Set vars
#
- id: set_vars
shell: bash
run: |
export BRANCH_NAME=${{ github.head_ref || github.ref_name }}
echo "SOURCE_REF_NAME=${BRANCH_NAME//\//-}" >> $GITHUB_OUTPUT
echo "COMMIT_SHA=${{ github.event.pull_request.head.sha || github.sha }}" >> $GITHUB_OUTPUT


- name: log
shell: bash
run: |
echo "action dir: ${{ steps.current_file.outputs.currentActionDir }}"
echo "wf file: ${{ steps.current_file.outputs.currentWorkflowFile }}"
echo "Modified: ${{ steps.set_changes.outputs.modified_keys }}"
echo "github.ref: ${{ github.ref }}"
echo "github.ref_name: ${{ github.ref_name }}"
echo "github.sha: ${{ github.sha }}"
Loading