2024-08-12 09:09:08 +02:00
|
|
|
name: Build Docker images for PRs
|
2021-10-07 10:50:47 +02:00
|
|
|
|
|
|
|
on:
|
|
|
|
pull_request:
|
|
|
|
branches:
|
|
|
|
- main
|
|
|
|
|
2023-01-30 11:53:45 +01:00
|
|
|
concurrency:
|
|
|
|
group: ${{ github.workflow }}-$${{ github.head_ref || github.run_id }}
|
|
|
|
cancel-in-progress: true
|
|
|
|
|
2021-10-07 10:50:47 +02:00
|
|
|
jobs:
|
|
|
|
build:
|
|
|
|
runs-on: ubuntu-latest
|
2023-02-28 14:17:50 +01:00
|
|
|
permissions: write-all
|
2021-10-07 10:50:47 +02:00
|
|
|
steps:
|
2024-03-13 13:43:06 +01:00
|
|
|
- uses: actions/checkout@v4
|
2022-01-30 10:54:26 +01:00
|
|
|
with:
|
|
|
|
fetch-depth: 2
|
2022-01-30 10:49:15 +01:00
|
|
|
- name: Get changed files
|
|
|
|
id: changed-files
|
2024-03-13 13:43:06 +01:00
|
|
|
uses: dorny/paths-filter@v3
|
2022-01-30 10:49:15 +01:00
|
|
|
with:
|
2024-03-13 13:43:06 +01:00
|
|
|
filters: |
|
|
|
|
files:
|
|
|
|
- '*.nix'
|
|
|
|
- 'go.*'
|
|
|
|
- '**/*.go'
|
|
|
|
- 'integration_test/'
|
|
|
|
- 'config-example.yaml'
|
2024-08-12 09:15:15 +02:00
|
|
|
- '.ko.yaml'
|
2023-06-28 12:56:35 +02:00
|
|
|
- uses: DeterminateSystems/nix-installer-action@main
|
2024-03-13 13:43:06 +01:00
|
|
|
if: steps.changed-files.outputs.files == 'true'
|
2023-06-28 12:56:35 +02:00
|
|
|
- uses: DeterminateSystems/magic-nix-cache-action@main
|
2024-03-13 13:43:06 +01:00
|
|
|
if: steps.changed-files.outputs.files == 'true'
|
2021-10-07 10:50:47 +02:00
|
|
|
|
2024-08-12 09:09:08 +02:00
|
|
|
- uses: actions/github-script@v6
|
|
|
|
id: get_pr_data
|
2023-02-28 14:17:50 +01:00
|
|
|
with:
|
|
|
|
script: |
|
2024-08-12 09:09:08 +02:00
|
|
|
return (
|
|
|
|
await github.rest.repos.listPullRequestsAssociatedWithCommit({
|
|
|
|
commit_sha: context.sha,
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
})
|
|
|
|
).data[0];
|
|
|
|
|
2024-08-12 09:22:29 +02:00
|
|
|
- name: Issue number
|
|
|
|
run: echo '${{steps.get_pr_data.outputs.result}}'
|
|
|
|
|
2024-08-12 09:09:08 +02:00
|
|
|
- name: Run ko build
|
|
|
|
id: build
|
2024-03-13 13:43:06 +01:00
|
|
|
if: steps.changed-files.outputs.files == 'true'
|
2024-08-12 09:09:08 +02:00
|
|
|
env:
|
|
|
|
KO_DOCKER_REPO: ghcr.io/${{ github.repository_owner }}/headscale
|
2024-08-12 09:16:50 +02:00
|
|
|
TAG_PR_NAME: pr-${{ fromJson(steps.get_pr_data.outputs.result).number }}
|
|
|
|
TAG_SHA: ${{ github.sha }}
|
2024-08-12 09:09:08 +02:00
|
|
|
run: |
|
2024-08-12 09:18:04 +02:00
|
|
|
echo $TAG_PR_NAME
|
|
|
|
ko build --tags=$TAG_SHA ./cmd/headscale
|