Skip to content

Commit

Permalink
Move diff generation workflow to this repository
Browse files Browse the repository at this point in the history
This avoids issues with GitHub token permissions across pull requests from forks
  • Loading branch information
aj-foster authored Jul 8, 2024
1 parent 8a68845 commit d18105d
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 12 deletions.
14 changes: 2 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ jobs:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ hashFiles('mix.lock') }}
key: ${{ runner.os }}-mix-${{matrix.pair.otp}}-${{ hashFiles('mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-
${{ runner.os }}-mix-${{matrix.pair.otp}}-
- name: Check Code Format
run: mix format --check-formatted
Expand All @@ -59,13 +59,3 @@ jobs:
name: Results
path: _build/test/lib/oapi_generator/*.xml
reporter: java-junit

diff:
name: "Generate Diff"
runs-on: ubuntu-latest
steps:
- name: Dispatch Workflow
env:
GH_TOKEN: ${{ secrets.DIFF_TOKEN }}
run: |
gh workflow run generate.yml --repo aj-foster/open-api-diffs --field ref=$GITHUB_HEAD_REF
73 changes: 73 additions & 0 deletions .github/workflows/generate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Generate

on:
push:
branches:
- main
pull_request: {}
workflow_dispatch:
inputs:
ref:
description: Ref of aj-foster/open-api-generator
required: true
type: string

permissions:
contents: write

jobs:
generate:
name: Generate Diff
runs-on: ubuntu-latest
steps:
- name: Setup Ref (Push)
if: github.event_name == 'pull_request'
run: |
echo "REF=main" >> $GITHUB_ENV
- name: Setup Ref (Pull Request)
if: github.event_name == 'pull_request'
run: |
echo "REF=$GITHUB_HEAD_REF" >> $GITHUB_ENV
- name: Setup Ref (Workflow Dispatch)
if: github.event_name == 'workflow_dispatch'
run: |
echo "REF=${{ inputs.ref }}" >> $GITHUB_ENV
- name: Checkout (Diffs)
uses: actions/checkout@v4
with:
repository: "aj-foster/open-api-diffs"
ref: main
path: diffs

- name: Checkout (Generator)
uses: actions/checkout@v4
with:
repository: "aj-foster/open-api-generator"
path: generator

- name: Setup BEAM
uses: erlef/setup-beam@v1
with:
otp-version: "27.0"
elixir-version: "1.17.1"

- name: Generate Code
run: |
cd diffs/
elixir generate.exs "$REF"
- name: Save Code
run: |
cd generator/
git checkout --orphan temporary-branch
git rm -rf .
mv ../diffs/output .
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add output/
git commit -m "Generated output for aj-foster/open-api-generator@$REF"
git tag -f "_diff/$REF"
git push --tags --force

0 comments on commit d18105d

Please sign in to comment.