|
| 1 | +name: Dependency submission |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [development, main] |
| 6 | + pull_request: |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: dependency-submission-${{ github.workflow }}-${{ github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +permissions: |
| 14 | + contents: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + submit-dependencies: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout target project |
| 22 | + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 |
| 23 | + with: |
| 24 | + path: project |
| 25 | + |
| 26 | + - name: Checkout cabal-plan-submit |
| 27 | + uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0' |
| 28 | + with: |
| 29 | + repository: dancewithheart/cabal-plan-submit |
| 30 | + path: cabal-plan-submit |
| 31 | + |
| 32 | + - name: Setup Haskell |
| 33 | + uses: haskell-actions/setup@cd0d9bdd65b20557f41bea4dbe43d0b5fbbfe553 # v2.11.0' |
| 34 | + with: |
| 35 | + ghc-version: "9.10.3" |
| 36 | + cabal-version: "3.16.1.0" |
| 37 | + |
| 38 | + - name: Cache Cabal store |
| 39 | + uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0' |
| 40 | + with: |
| 41 | + path: | |
| 42 | + ~/.cabal/store |
| 43 | + ~/.cabal/packages |
| 44 | + cabal-plan-submit/dist-newstyle |
| 45 | + project/dist-newstyle |
| 46 | + key: ${{ runner.os }}-ghc-9.10.3-${{ hashFiles('project/**/*.cabal', 'project/cabal.project*', 'cabal-plan-submit/**/*.cabal', 'cabal-plan-submit/cabal.project*') }} |
| 47 | + restore-keys: | |
| 48 | + ${{ runner.os }}-ghc-9.10.3- |
| 49 | +
|
| 50 | + - name: Configure environment |
| 51 | + run: | |
| 52 | + ./.github/workflows/setup.sh |
| 53 | + cabal update |
| 54 | +
|
| 55 | + - name: Build target project |
| 56 | + working-directory: project |
| 57 | + run: cabal build all --dry-run |
| 58 | + |
| 59 | + - name: Build cabal-plan-submit |
| 60 | + working-directory: cabal-plan-submit |
| 61 | + run: cabal build exe:cabal-plan-submit |
| 62 | + |
| 63 | + - name: Render and validate dependency snapshot |
| 64 | + working-directory: project |
| 65 | + env: |
| 66 | + SHA: ${{ github.sha }} |
| 67 | + REF: ${{ github.ref }} |
| 68 | + run: | |
| 69 | + BIN="$(cd ../cabal-plan-submit && cabal list-bin exe:cabal-plan-submit | tail -n 1)" |
| 70 | + "$BIN" render-snapshot dist-newstyle/cache/plan.json "$SHA" "$REF" > ../snapshot.json |
| 71 | + "$BIN" validate-snapshot ../snapshot.json |
| 72 | +
|
| 73 | + - name: Submit dependency snapshot |
| 74 | + env: |
| 75 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 76 | + REPO: ${{ github.repository }} |
| 77 | + run: | |
| 78 | + owner="${REPO%/*}" |
| 79 | + repo="${REPO#*/}" |
| 80 | +
|
| 81 | + response="$( |
| 82 | + curl \ |
| 83 | + --fail-with-body \ |
| 84 | + -X POST \ |
| 85 | + -H "Accept: application/vnd.github+json" \ |
| 86 | + -H "Authorization: Bearer $GITHUB_TOKEN" \ |
| 87 | + -H "X-GitHub-Api-Version: 2022-11-28" \ |
| 88 | + "https://api.github.com/repos/$owner/$repo/dependency-graph/snapshots" \ |
| 89 | + --data-binary @snapshot.json |
| 90 | + )" |
| 91 | +
|
| 92 | + echo "$response" | jq . |
| 93 | +
|
| 94 | + snapshot_id="$(echo "$response" | jq -r '.id')" |
| 95 | + snapshot_url="https://api.github.com/repos/$owner/$repo/dependency-graph/snapshots/$snapshot_id" |
| 96 | +
|
| 97 | + echo "Snapshot API URL: $snapshot_url" |
| 98 | + echo "Snapshot result: $(echo "$response" | jq -r '.result')" |
| 99 | + echo "Snapshot message: $(echo "$response" | jq -r '.message')" |
0 commit comments