|
| 1 | +name: "Copilot Setup Steps" |
| 2 | + |
| 3 | +# Automatically run the setup steps when they are changed |
| 4 | +# Allows for streamlined validation, |
| 5 | +# and allow manual testing through the repository's "Actions" tab |
| 6 | + |
| 7 | +on: |
| 8 | + workflow_dispatch: |
| 9 | + push: |
| 10 | + paths: |
| 11 | + - .github/workflows/copilot-setup-steps.yml |
| 12 | + pull_request: |
| 13 | + paths: |
| 14 | + - .github/workflows/copilot-setup-steps.yml |
| 15 | + |
| 16 | +env: |
| 17 | + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} |
| 18 | + |
| 19 | +jobs: |
| 20 | + # The job MUST be called `copilot-setup-steps` |
| 21 | + # otherwise it will not be picked up by Copilot. |
| 22 | + copilot-setup-steps: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + |
| 25 | + # Permissions set just for the setup steps |
| 26 | + # Copilot has permissions to its branch |
| 27 | + |
| 28 | + permissions: |
| 29 | + # To allow us to clone the repo for setup |
| 30 | + contents: read |
| 31 | + |
| 32 | + # The setup steps - install our dependencies |
| 33 | + steps: |
| 34 | + - name: Setup Java |
| 35 | + uses: actions/setup-java@v4 |
| 36 | + with: |
| 37 | + distribution: 'temurin' |
| 38 | + java-version: '21' |
| 39 | + |
| 40 | + - name: Setup Gradle |
| 41 | + uses: gradle/actions/setup-gradle@v4 |
| 42 | + with: |
| 43 | + gradle-version: current |
| 44 | + |
| 45 | + - name: Checkout Kadabra |
| 46 | + uses: actions/checkout@v6 |
| 47 | + with: |
| 48 | + path: kadabra |
| 49 | + |
| 50 | + - name: Determine repository refs |
| 51 | + id: repo-refs |
| 52 | + shell: bash |
| 53 | + env: |
| 54 | + BRANCH_NAME: ${{ env.BRANCH_NAME }} |
| 55 | + BASE_BRANCH: ${{ github.base_ref }} |
| 56 | + run: | |
| 57 | + set -euo pipefail |
| 58 | +
|
| 59 | + # For each dependency repository, determine which branch to checkout. |
| 60 | + # Priority order: |
| 61 | + # 1. A branch with the same name as the current branch |
| 62 | + # 2. If this is a PR, the target branch (base_ref) |
| 63 | + # 3. The default branch of the repository |
| 64 | +
|
| 65 | + determine_ref() { |
| 66 | + local prefix=$1 |
| 67 | + local repo=$2 |
| 68 | + local url="https://github.com/${repo}.git" |
| 69 | +
|
| 70 | + # Get the default branch |
| 71 | + local default_branch |
| 72 | + default_branch=$(git ls-remote --symref "$url" HEAD | awk '/^ref:/ {print $2}' | sed 's@refs/heads/@@') |
| 73 | + echo "${prefix}_default=${default_branch}" >> "$GITHUB_OUTPUT" |
| 74 | + echo "Default branch for ${repo} is '${default_branch}'" |
| 75 | +
|
| 76 | + local ref_to_use="" |
| 77 | + |
| 78 | + # Priority 1: Same branch name |
| 79 | + if [ -n "$(git ls-remote --heads "$url" "refs/heads/${BRANCH_NAME}")" ]; then |
| 80 | + ref_to_use="${BRANCH_NAME}" |
| 81 | + echo "Using matching branch '${BRANCH_NAME}' in ${repo}" |
| 82 | + # Priority 2: PR target branch (if this is a PR) |
| 83 | + elif [ -n "${BASE_BRANCH}" ] && [ -n "$(git ls-remote --heads "$url" "refs/heads/${BASE_BRANCH}")" ]; then |
| 84 | + ref_to_use="${BASE_BRANCH}" |
| 85 | + echo "Using PR target branch '${BASE_BRANCH}' in ${repo}" |
| 86 | + # Priority 3: Default branch |
| 87 | + else |
| 88 | + ref_to_use="${default_branch}" |
| 89 | + echo "Using default branch '${default_branch}' for ${repo}" |
| 90 | + fi |
| 91 | + |
| 92 | + echo "${prefix}_ref=${ref_to_use}" >> "$GITHUB_OUTPUT" |
| 93 | + } |
| 94 | +
|
| 95 | + determine_ref "lara" "specs-feup/lara-framework" |
| 96 | + determine_ref "specs" "specs-feup/specs-java-libs" |
| 97 | +
|
| 98 | + - name: Echo checks |
| 99 | + run: | |
| 100 | + echo "Weaver branch: ${{ env.BRANCH_NAME }}" |
| 101 | + echo "PR target branch (if any): ${{ github.base_ref }}" |
| 102 | + echo "Lara framework ref: ${{ steps.repo-refs.outputs.lara_ref }}" |
| 103 | + echo "Lara framework default: ${{ steps.repo-refs.outputs.lara_default }}" |
| 104 | + echo "Specs-java-libs ref: ${{ steps.repo-refs.outputs.specs_ref }}" |
| 105 | + echo "Specs-java-libs default: ${{ steps.repo-refs.outputs.specs_default }}" |
| 106 | +
|
| 107 | + - name: Checkout lara-framework |
| 108 | + uses: actions/checkout@v6 |
| 109 | + with: |
| 110 | + repository: specs-feup/lara-framework |
| 111 | + path: lara-framework |
| 112 | + ref: ${{ steps.repo-refs.outputs.lara_ref }} |
| 113 | + |
| 114 | + - name: Checkout specs-java-libs |
| 115 | + uses: actions/checkout@v6 |
| 116 | + with: |
| 117 | + repository: specs-feup/specs-java-libs |
| 118 | + path: specs-java-libs |
| 119 | + ref: ${{ steps.repo-refs.outputs.specs_ref }} |
0 commit comments