diff --git a/.github/workflows/test-github-actions.yaml b/.github/workflows/test-github-actions.yaml index 26009e6..0d0d863 100644 --- a/.github/workflows/test-github-actions.yaml +++ b/.github/workflows/test-github-actions.yaml @@ -50,7 +50,27 @@ jobs: run: | cat output.txt test "$(cat output.txt)" = "Hello world" - test-pull-single-file: + test-pull-single-file-1: + runs-on: ubuntu-22.04 + steps: + - name: Create simple template with variable + run: | + echo "Hello {{ name }}" > template.j2 + - name: Create data file + run: | + echo "name: world" > data.yaml + - name: Render template + # LTODO: switch to main branch + uses: everest/everest-ci/github-actions/render-jinja2@feature/add-render-jinja2-action + with: + template_file: template.j2 + data_file: data.yaml + output_file: output.txt + - name: Check output + run: | + cat output.txt + test "$(cat output.txt)" = "Hello world" + test-pull-single-file-2: runs-on: ubuntu-22.04 steps: - name: Setup SSH @@ -65,7 +85,7 @@ jobs: with: # LTODO: switch to main branch github_path: everest/everest-ci/.github/workflows/test-github-actions.yaml@feature/add-render-jinja2-action - output_path: output.txt + output_path: . - name: Checkout everest-ci uses: actions/checkout@v2 with: @@ -89,17 +109,17 @@ jobs: echo "output_directory: ${{ steps.pull-single-file.outputs.output_directory }}" test "${{ steps.pull-single-file.outputs.output_directory }}" = "$(pwd)" echo "output_filename: ${{ steps.pull-single-file.outputs.output_filename }}" - test "${{ steps.pull-single-file.outputs.output_filename }}" = "output.txt" + test "${{ steps.pull-single-file.outputs.output_filename }}" = "test-github-actions.yaml" - name: Check output file run: | - cat output.txt - test "$(cat output.txt)" = "$(cat everest-ci/.github/workflows/test-github-actions.yaml)" - test-configure-ssh: + cat ${{ steps.pull-single-file.outputs.output_filename }} + test "$(cat ${{ steps.pull-single-file.outputs.output_filename }})" = "$(cat everest-ci/.github/workflows/test-github-actions.yaml)" + test-configure-git: runs-on: ubuntu-22.04 steps: - - name: Configure SSH + - name: Configure Git # LTODO: switch to main branch - uses: everest/everest-ci/github-actions/configure-ssh@feature/add-render-jinja2-action + uses: everest/everest-ci/github-actions/configure-git@feature/add-render-jinja2-action with: email: compiler@pionix.de name: Github Service Account diff --git a/github-actions/configure-ssh/action.yaml b/github-actions/configure-git/action.yaml similarity index 84% rename from github-actions/configure-ssh/action.yaml rename to github-actions/configure-git/action.yaml index e7eb476..3f6d5f8 100644 --- a/github-actions/configure-ssh/action.yaml +++ b/github-actions/configure-git/action.yaml @@ -1,5 +1,5 @@ -name: Configure ssh email and name -description: Configure ssh email and name +name: Configure git email and name +description: Configure git email and name inputs: email: description: 'Email' diff --git a/github-actions/pull-single-file/action.yaml b/github-actions/pull-single-file/action.yaml index 0d2fc01..acfde15 100644 --- a/github-actions/pull-single-file/action.yaml +++ b/github-actions/pull-single-file/action.yaml @@ -55,12 +55,13 @@ runs: run: | import os, pathlib directory = None - if "${{ inputs.output_path }}".endswith('/'): - directory = pathlib.Path("${{ inputs.output_path }}") + output_path = "${{ inputs.output_path }}" + if output_path.endswith('/') or output_path == '.' or output_path == '..': + directory = pathlib.Path(output_path) filename = "${{ steps.extracted.outputs.filename }}" else: - directory = pathlib.Path("${{ inputs.output_path }}").parent - filename = pathlib.Path("${{ inputs.output_path }}").name + directory = pathlib.Path(output_path).parent + filename = pathlib.Path(output_path).name directory.mkdir(parents=True, exist_ok=True) with open(os.environ['GITHUB_OUTPUT'], 'a') as f: f.write(f'directory={ directory.absolute() }\n') @@ -73,4 +74,14 @@ runs: git archive HEAD:${{ steps.extracted.outputs.directory }} ${{ steps.extracted.outputs.filename }} | tar -C ${{ steps.prepare-output.outputs.directory }} -xf - cd .. rm -rf tmp-repo - mv ${{ steps.prepare-output.outputs.directory }}/${{ steps.extracted.outputs.filename }} ${{ steps.prepare-output.outputs.directory }}/${{ steps.prepare-output.outputs.filename }} + - name: Rename file if necessary + shell: bash + run: | + directory="${{ steps.prepare-output.outputs.directory }}" + source="$directory/${{ steps.extracted.outputs.filename }}" + target="$directory/${{ steps.prepare-output.outputs.filename }}" + if test "$source" = "$target"; then + echo "File $source is already named $target" + else + mv $source $target + fi \ No newline at end of file