From 6be290e02f536c98ee827f1f02a2b14d44e9c0f2 Mon Sep 17 00:00:00 2001 From: Nikita Volodin Date: Mon, 10 Jun 2024 00:18:56 -0400 Subject: [PATCH] fix(.github): fix actionsflow workflow Since the recent release of act, it now fails when there are no workflow files to execute. In particular because of this PR: https://github.com/nektos/act/pull/2272. With this fix, we now only run act when the workflow files were generated by actionsflow. --- .github/workflows/actionsflow.yaml | 59 ++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-) diff --git a/.github/workflows/actionsflow.yaml b/.github/workflows/actionsflow.yaml index 3f4dc9e73..f7babe302 100644 --- a/.github/workflows/actionsflow.yaml +++ b/.github/workflows/actionsflow.yaml @@ -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 @@ -51,8 +55,47 @@ jobs: json-secrets: ${{ toJSON(secrets) }} json-github: ${{ toJSON(github) }} + - name: Check workflow files + id: check-workflow-files + run: |- + 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 @@ -67,3 +110,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, + })