Skip to content

feat: specify artifact name #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions .github/workflows/test-artifact-name.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Test example artifact name overridden
on:
push:
# # Uncomment when test added first time to register workflow and comment it back after workflow would be registered
# #
# # Added pull_request to register workflow from the PR.
# # Read more https://stackoverflow.com/questions/63362126/github-actions-how-to-run-a-workflow-created-on-a-non-master-branch-from-the-wo
# pull_request: {}
workflow_dispatch: {}

jobs:
setup:
runs-on: ubuntu-latest
strategy:
matrix:
target: ["one", "two"]
steps:
- name: Setup
run: echo "Do setup"

- name: Checkout
uses: actions/checkout@v4

- uses: ./
id: writer
with:
matrix-step-name: setup1
matrix-key: ${{ matrix.target }}
artifact-name: setup1
outputs: |-
result: ${{ matrix.target }}
test: existing_value

- uses: nick-fields/assert-action@v2
with:
expected: ${{ matrix.target }}
actual: ${{ fromJson(steps.writer.outputs.result).result }}

- uses: nick-fields/assert-action@v2
with:
expected: existing_value
actual: ${{ fromJson(steps.writer.outputs.result).test }}

setup2:
runs-on: ubuntu-latest
strategy:
matrix:
target: ["one", "two"]
steps:
- name: Setup
run: echo "Do setup"

- name: Checkout
uses: actions/checkout@v4

- uses: ./
id: writer
with:
matrix-step-name: setup2
matrix-key: ${{ matrix.target }}
artifact-name: setup2
outputs: |-
result: ${{ matrix.target }}
test: existing_value

- uses: nick-fields/assert-action@v2
with:
expected: ${{ matrix.target }}
actual: ${{ fromJson(steps.writer.outputs.result).result }}

- uses: nick-fields/assert-action@v2
with:
expected: existing_value
actual: ${{ fromJson(steps.writer.outputs.result).test }}

test:
runs-on: ubuntu-latest
continue-on-error: true
needs: [setup]
steps:
- uses: actions/download-artifact@v4

- id: current
run: |-
echo "result=$(ls | wc -l)" >> $GITHUB_OUTPUT

outputs:
result: "${{ steps.current.outputs.result }}"
outcome: "${{ steps.current.outcome }}"

assert:
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: nick-fields/assert-action@v2
with:
expected: '4'
actual: "${{ needs.test.outputs.result }}"

- uses: nick-fields/assert-action@v2
with:
expected: 'success'
actual: "${{ needs.test.outputs.outcome }}"

teardown:
runs-on: ubuntu-latest
needs: [assert]
if: ${{ always() }}
steps:
- name: Tear down
run: echo "Do Tear down"
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
matrix-key:
required: false
description: "Matrix key"
artifact-name:
required: false
description: "Override the name used to store the artifact (default is a hash of the content)"
outputs:
required: false
description: "YAML structured map of outputs"
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const fs = require('fs');
try {
const step_name = core.getInput('matrix-step-name');
const matrix_key = core.getInput('matrix-key');
const artifact_name = core.getInput('artifact-name');
const outputs = core.getInput('outputs');

core.debug("step_name:")
Expand All @@ -15,6 +16,9 @@ try {
core.debug("matrix_key:")
core.debug(matrix_key)

core.debug("artifact_name:")
core.debug(artifact_name)

core.debug("outputs:")
core.debug(outputs)

Expand Down Expand Up @@ -74,7 +78,7 @@ ${error}`;
const hex = hashSum.digest('hex');

const artifactClient = new DefaultArtifactClient();
const artifactName = hex;
const artifactName = isEmptyInput(artifact_name) ? hex : artifact_name + matrix_key;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hesitated here to rename the artifactName const to something else to differentiate them. However since I noticed inputs are in snake case, I thought maybe that's your convention to differentiate inputs form the rest and that's enough

const files = [
"./" + step_name,
]
Expand Down