From b9c3af7df93fa794806020269edb88bf06099e35 Mon Sep 17 00:00:00 2001 From: Nikita Volodin Date: Mon, 10 Jun 2024 00:18:56 -0400 Subject: [PATCH] feat(.github): split gen/exec of actionsflow workflows This change separates the generation of workflow files by actionsflow from the execution of those workflow files using nektos/act project. The generated files are shared between jobs by uploading an artifact to github. The artifact is always deleted, even if running act was unsuccessful. --- .github/workflows/actionsflow.yaml | 43 +++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/.github/workflows/actionsflow.yaml b/.github/workflows/actionsflow.yaml index 504846dd1..b54aeebd0 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 @@ -58,6 +62,29 @@ jobs: 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: Install act if: ${{ steps.check-workflow-files.outputs.present == 'true' }} run: curl -fsSL https://raw.githubusercontent.com/nektos/act/master/install.sh | bash -s -- -b ~/bin/ @@ -77,3 +104,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, + })