Skip to content

Fix syntax error in example (#159) #25

Fix syntax error in example (#159)

Fix syntax error in example (#159) #25

Workflow file for this run

name: Build
on:
push:
branches:
- main
workflow_call:
workflow_dispatch:
permissions:
contents: write
concurrency:
group: nyx-main-build
cancel-in-progress: true
jobs:
build:
runs-on: nyxbuilder
timeout-minutes: 1440
steps:
- name: Check if already cached
id: check
if: github.event_name == 'push'
continue-on-error: true
uses: actions/github-script@v6
with:
script: |
const valid = await github.rest.repos.compareCommits({
owner: context.repo.owner,
repo: context.repo.repo,
base: 'nyxpkgs-unstable',
head: context.sha
}).then((response) => response.data.status == "ahead" && response.data.ahead_by == 1)
// Needs to be ahead by 1 commit exactly, otherwise we don't consider this PR as being potentially cached
if (valid) {
// Equivalent for js from perl: '(?<=\(#)\d+(?=\)$)'
const PARSED_MESSAGE = context.payload.head_commit.message.split('\n')[0].match(/\(#(\d+)\)$/)
const PR_NUMBER = PARSED_MESSAGE ? PARSED_MESSAGE[1] : null
if (PR_NUMBER) {
await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: PR_NUMBER
}).then((response) => {
const OUTPUT = response.data;
const PR_LABELS = OUTPUT.labels.map((label) => label.name)
const BASE_COMMIT = OUTPUT.base.sha
const MERGE_COMMIT = OUTPUT.merge_commit_sha
if (PR_LABELS.includes('cached') && BASE_COMMIT === context.payload.before && MERGE_COMMIT === context.sha) {
// Exit with a non-zero exit code to skip the rest of the job
console.log("Already cached, skipping build.");
core.setOutput("cached", true)
}
}).catch((error) => {
console.log("Github rest API error encountered, assuming not cached.")
})
}
}
- name: Install Nix
if: (success() && steps.check.outputs.cached != 'true')
uses: cachix/install-nix-action@v21
with:
extra_nix_config: "accept-flake-config = true"
# Checkout the main branch
- name: Checkout
if: (success() && steps.check.outputs.cached != 'true')
uses: actions/checkout@v2
with:
ref: main
- name: Build
if: (success() && steps.check.outputs.cached != 'true')
continue-on-error: true
id: build
run: |
nix develop -c build-chaotic-nyx || [ $? -eq 42 ]
failed_builds="$(cat ${{ runner.temp }}/failures.txt | sed 's/^/ <li>/; s/$/<\/li>/')"
failed_builds_count="$(cat ${{ runner.temp }}/failures.txt | wc -l)"
echo "FAILED_BUILDS_COUNT=$failed_builds_count
FAILED_BUILDS<<EOF
$failed_builds
EOF" >> $GITHUB_OUTPUT
env:
NYX_WD: ${{ runner.temp }}
CACHIX_AUTH_TOKEN: ${{ secrets.CACHIX_AUTH_TOKEN }}
- name: Update nyxpkgs-unstable
if: (success() && steps.check.outputs.cached != 'true')
run: git push origin HEAD:nyxpkgs-unstable --force
- name: Comment on commit
if: (success() && steps.check.outputs.cached != 'true')
uses: actions/github-script@v6
with:
script: |
if (process.env.FAILED_BUILDS_COUNT > 0)
github.rest.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
body: `Failed to build $FAILED_BUILDS_COUNT packages:
<details>
<summary>${process.env.FAILED_BUILDS_COUNT} packages failed</summary>
<ul>
${process.env.FAILED_BUILDS}
</ul>
</details>`
})
else
github.rest.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
body: 'All packages were built and cached successfully!'
})
env:
FAILED_BUILDS_COUNT: ${{ steps.build.outputs.FAILED_BUILDS_COUNT }}
FAILED_BUILDS: ${{ steps.build.outputs.FAILED_BUILDS }}