Skip to content

Commit

Permalink
fix(.github): fix actionsflow workflow
Browse files Browse the repository at this point in the history
Since the recent release of act, it now fails when there are no workflow files
to execute. In particular because of this PR:
nektos/act#2272. With this fix, we now only run act
when the workflow files were generated by actionsflow.
  • Loading branch information
qlonik committed Jun 10, 2024
1 parent 46556eb commit c1d0ff6
Showing 1 changed file with 59 additions and 3 deletions.
62 changes: 59 additions & 3 deletions .github/workflows/actionsflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ on:
required: false
default: "false"

concurrency: actionsflow

jobs:
run:
generate-workflows:
name: Generate workflows from Actionsflow
runs-on: ["gha-home-ops"]
name: Run
concurrency: actionsflow
outputs:
run-act: ${{ steps.check-workflow-files.outputs.present }}
artifact-id: ${{ steps.upload-configs.outputs.artifact-id }}
steps:
- uses: actions/checkout@v4

Expand All @@ -51,8 +55,50 @@ jobs:
json-secrets: ${{ toJSON(secrets) }}
json-github: ${{ toJSON(github) }}

- name: Check workflow files
id: check-workflow-files
run: |-
ls -alhR ./dist
tree ./dist
if [[ -d "./dist/workflows" && ! -z "ls -A ./dist/workflows" ]]; then
echo "present=true" >> "$GITHUB_OUTPUT"
fi
- name: Upload generated workflows
id: upload-configs
if: ${{ steps.check-workflow-files.outputs.present == 'true' }}
uses: actions/upload-artifact@v4
with:
name: actionsflow-act-config
path: ./dist
if-no-files-found: error
retention-days: 1

run-act:
name: Run act
runs-on: ["gha-home-ops"]
needs: generate-workflows
if: ${{ needs.generate-workflows.outputs.run-act == 'true' }}
steps:
- uses: actions/checkout@v4

- uses: actions/download-artifact@v4
with:
name: actionsflow-act-config
path: ./dist

- name: list artifacts
run: |-
echo "list workdir"
ls -alh $GITHUB_WORKSPACE
echo "list dist"
ls -alhR dist/
- name: Install act
run: curl -fsSL https://raw.githubusercontent.com/nektos/act/master/install.sh | bash -s -- -b ~/bin/

- name: Run act
# Consider adding support for cache artifacts
# https://github.com/nektos/act/issues/329#issuecomment-1187246629
Expand All @@ -67,3 +113,13 @@ jobs:
--secret-file ./dist/.secrets \
--env-file ./dist/.env \
--platform ubuntu-latest=ghcr.io/catthehacker/ubuntu:act-latest
- name: Delete artifacts
if: ${{ always() }}
uses: actions/github-script@v7
with:
script: |
github.rest.actions.deleteArtifact({
artifact_id: "${{ needs.generate-workflows.outputs.artifact-id }}",
...context.repo,
})

0 comments on commit c1d0ff6

Please sign in to comment.