### Install project dependencies Source: https://github.com/actions/upload-artifact/blob/main/CONTRIBUTING.md Run this command to install all necessary dependencies for the project. ```bash npm install ``` -------------------------------- ### Upload Artifact Action Example Source: https://github.com/actions/upload-artifact/blob/main/merge/README.md This example demonstrates how to upload multiple artifacts using a matrix strategy. Each artifact is named based on the matrix configuration. ```yaml jobs: upload: runs-on: ubuntu-latest strategy: matrix: foo: [a, b, c] steps: - name: Run a one-line script run: echo "hello from job ${{ matrix.foo }}" > file-${{ matrix.foo }}.txt - name: Upload uses: actions/upload-artifact@v4 with: name: my-artifact-${{ matrix.foo }} path: file-${{ matrix.foo }}.txt ``` -------------------------------- ### Set Artifact Retention and Compression Level Source: https://github.com/actions/upload-artifact/blob/main/merge/README.md This example demonstrates how to configure the retention period and compression level for the merged artifact. Adjust 'retention-days' for artifact lifespan and 'compression-level' for upload speed versus file size. ```yaml steps: - name: Configure retention and compression uses: actions/upload-artifact/merge@v4 with: name: "custom-retention-compression" retention-days: 30 compression-level: 9 ``` -------------------------------- ### Prefix Directories in Merged Artifact Source: https://github.com/actions/upload-artifact/blob/main/merge/README.md This example demonstrates how to merge artifacts while prefixing each original artifact's contents into a separate directory within the merged artifact. This helps maintain organization when dealing with numerous artifacts. ```yaml steps: - name: Merge artifacts into separate directories uses: actions/upload-artifact/merge@v4 with: name: "prefixed-artifacts" separate-directories: true ``` -------------------------------- ### Upload hidden files in v3 Source: https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md Example of uploading a hidden file using v3, where hidden files were included by default. ```yaml jobs: upload: runs-on: ubuntu-latest steps: - name: Create a Hidden File run: echo "hello from a hidden file" > .hidden-file.txt - name: Upload Artifact uses: actions/upload-artifact@v3 with: path: .hidden-file.txt ``` -------------------------------- ### Merge All Artifacts in Workflow Run Source: https://github.com/actions/upload-artifact/blob/main/merge/README.md This example shows how to merge all artifacts generated in a workflow run into a single artifact named 'merged-artifacts'. This is useful when you need to consolidate multiple outputs into one for easier download or management. ```yaml steps: - name: Merge all artifacts uses: actions/upload-artifact/merge@v4 ``` -------------------------------- ### Multiple Uploads to Same Artifact (v3) Source: https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md In v3, artifacts are mutable, allowing multiple jobs to upload to the same artifact name. This example shows how different jobs upload files to 'my-artifact'. ```yaml jobs: upload: strategy: matrix: runs-on: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.runs-on }} steps: - name: Create a File run: echo "hello from ${{ matrix.runs-on }}" > file-${{ matrix.runs-on }}.txt - name: Upload Artifact uses: actions/upload-artifact@v3 with: name: my-artifact # NOTE: same artifact name path: file-${{ matrix.runs-on }}.txt download: needs: upload runs-on: ubuntu-latest steps: - name: Download All Artifacts uses: actions/download-artifact@v3 with: name: my-artifact path: my-artifact - run: ls -R my-artifact ``` -------------------------------- ### Include Hidden Files in Artifact Source: https://github.com/actions/upload-artifact/blob/main/README.md Upload hidden files, which are ignored by default. Hidden files are those starting with '.' or within directories starting with '.'. ```yaml - uses: actions/upload-artifact@v7 with: name: my-artifact include-hidden-files: true path: | path/output/ !path/output/.production.env ``` -------------------------------- ### Delete Artifacts After Merge Source: https://github.com/actions/upload-artifact/blob/main/merge/README.md This example shows how to merge artifacts and then automatically delete the original artifacts after the merge is complete. Use this option when the original artifacts are no longer needed. ```yaml steps: - name: Merge and delete original artifacts uses: actions/upload-artifact/merge@v4 with: name: "merged-and-deleted" delete-merged: true ``` -------------------------------- ### Include Hidden Files in Artifacts Source: https://context7.com/actions/upload-artifact/llms.txt Enable include-hidden-files: true to upload files starting with a dot, while using glob patterns to exclude sensitive files. ```yaml name: Upload with Hidden Files on: [push] jobs: upload: runs-on: ubuntu-latest steps: - name: Create directory with hidden files run: | mkdir config echo "app config" > config/.apprc echo "cache data" > config/.cache echo "SECRET=sensitive" > config/.env echo "public config" > config/settings.json - name: Upload Including Hidden Files (excluding secrets) uses: actions/upload-artifact@v7 with: name: config-files include-hidden-files: true path: | config/ !config/.env ``` -------------------------------- ### Overwriting Artifact Content (v3) Source: https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md In v3, artifacts are mutable, allowing subsequent uploads with the same name to overwrite previous content. This example demonstrates uploading 'my-file.txt' twice, with the second upload replacing the first. ```yaml jobs: upload: runs-on: ubuntu-latest steps: - name: Create a file run: echo "hello world" > my-file.txt - name: Upload Artifact uses: actions/upload-artifact@v3 with: name: my-artifact # NOTE: same artifact name path: my-file.txt upload-again: needs: upload runs-on: ubuntu-latest steps: - name: Create a different file run: echo "goodbye world" > my-file.txt - name: Upload Artifact uses: actions/upload-artifact@v3 with: name: my-artifact # NOTE: same artifact name path: my-file.txt ``` -------------------------------- ### Release project build Source: https://github.com/actions/upload-artifact/blob/main/CONTRIBUTING.md Update the entry-point file in the dist directory for the action. ```bash npm run release ``` -------------------------------- ### Configure Dynamic Paths for Artifacts Source: https://context7.com/actions/upload-artifact/llms.txt Demonstrates using environment variables, GitHub context expressions, and tilde expansion for artifact path configuration. ```yaml name: Dynamic Paths Example on: [push] env: BUILD_DIR: dist ARTIFACT_PREFIX: release jobs: build: runs-on: ubuntu-latest steps: - name: Create build output run: | mkdir -p ${{ github.workspace }}/${{ env.BUILD_DIR }} echo "Version: ${{ github.sha }}" > ${{ github.workspace }}/${{ env.BUILD_DIR }}/version.txt mkdir -p ~/artifacts echo "Home directory artifact" > ~/artifacts/home-file.txt - name: Set dynamic artifact path run: echo "ARTIFACT_PATH=${{ env.BUILD_DIR }}/version.txt" >> $GITHUB_ENV - name: Upload using workspace path uses: actions/upload-artifact@v7 with: name: ${{ env.ARTIFACT_PREFIX }}-${{ github.run_number }} path: ${{ github.workspace }}/${{ env.BUILD_DIR }}/**/* - name: Upload from home directory (tilde expansion) uses: actions/upload-artifact@v7 with: name: home-artifacts path: ~/artifacts/**/* - name: Upload using dynamic env path uses: actions/upload-artifact@v7 with: name: dynamic-artifact path: ${{ env.ARTIFACT_PATH }} ``` -------------------------------- ### Format project code Source: https://github.com/actions/upload-artifact/blob/main/CONTRIBUTING.md Run the formatter to ensure the code adheres to project style guidelines. ```bash npm run format ``` -------------------------------- ### Upload Artifact with Tilde Expansion in Path Source: https://github.com/actions/upload-artifact/blob/main/README.md Use tilde (~) in the 'path' input to represent the user's home directory. This allows for flexible artifact location specification. ```yaml - run: | mkdir -p ~/new/artifact echo hello > ~/new/artifact/world.txt - uses: actions/upload-artifact@v7 with: name: my-artifacts path: ~/new/**/* ``` -------------------------------- ### Run project tests Source: https://github.com/actions/upload-artifact/blob/main/CONTRIBUTING.md Execute the test suite to ensure the codebase is functioning as expected. ```bash npm run test ``` -------------------------------- ### Customize Behavior When No Files Are Found Source: https://github.com/actions/upload-artifact/blob/main/README.md Configure the 'if-no-files-found' input to control the action's behavior when no files match the specified path. Options include 'warn', 'error', or 'ignore'. Defaults to 'warn'. ```yaml - uses: actions/upload-artifact@v7 with: name: my-artifact path: path/to/artifact/ if-no-files-found: error # 'warn' or 'ignore' are also available, defaults to `warn` ``` -------------------------------- ### Create Large Random File for Testing Source: https://context7.com/actions/upload-artifact/llms.txt This command generates a 50MB binary file filled with random data, useful for testing upload speeds with incompressible content. ```bash - name: Create large random file run: dd if=/dev/urandom of=random-data.bin bs=1M count=50 ``` -------------------------------- ### actions/upload-artifact@v7 Source: https://github.com/actions/upload-artifact/blob/main/README.md Configuration parameters and output details for the upload-artifact action. ```APIDOC ## actions/upload-artifact@v7 ### Description Uploads files, directories, or wildcard patterns as artifacts to be stored with the workflow run. ### Parameters #### Request Body - **name** (string) - Optional - Name of the artifact to upload. Default is 'artifact'. - **path** (string) - Required - A file, directory or wildcard pattern that describes what to upload. - **if-no-files-found** (string) - Optional - Behavior if no files are found: 'warn', 'error', or 'ignore'. Default is 'warn'. - **retention-days** (integer) - Optional - Duration in days to keep the artifact. Min 1, Max 90. - **compression-level** (integer) - Optional - Zlib compression level (0-9). Default is 6. - **overwrite** (boolean) - Optional - If true, replaces existing artifact with same name. Default is 'false'. - **include-hidden-files** (boolean) - Optional - Whether to include hidden files. Default is 'false'. - **archive** (boolean) - Optional - Whether to zip the files. Default is 'true'. ### Response #### Outputs - **artifact-id** (string) - GitHub ID of an Artifact. - **artifact-url** (string) - URL to download the artifact. - **artifact-digest** (string) - SHA-256 digest of the artifact. ``` -------------------------------- ### Upload Artifact with No Compression Source: https://context7.com/actions/upload-artifact/llms.txt Use `compression-level: 0` for the fastest uploads, especially with binary or random data that is not easily compressible. ```yaml - name: Upload with No Compression uses: actions/upload-artifact@v7 with: name: binary-no-compression path: random-data.bin compression-level: 0 ``` -------------------------------- ### Lint project code Source: https://github.com/actions/upload-artifact/blob/main/CONTRIBUTING.md Execute the linter to check for code quality and syntax issues. ```bash npm run lint ``` -------------------------------- ### Upload Artifacts in GitHub Actions Source: https://context7.com/actions/upload-artifact/llms.txt Demonstrates various ways to upload files, directories, and filtered patterns using the upload-artifact action. ```yaml name: Build and Upload Artifacts on: [push] jobs: build: runs-on: ubuntu-latest steps: # Upload a single file - name: Create build output run: | mkdir -p build/ echo "Build output contents" > build/app.js - name: Upload Build Artifact uses: actions/upload-artifact@v7 with: name: build-output path: build/app.js # Upload an entire directory - name: Upload Full Build Directory uses: actions/upload-artifact@v7 with: name: full-build path: build/ # Upload using wildcard patterns with exclusions - name: Create test reports run: | mkdir -p reports/ echo "Test results" > reports/test-results.xml echo "Coverage data" > reports/coverage.json echo "Temp file" > reports/temp.tmp - name: Upload Reports (excluding temp files) uses: actions/upload-artifact@v7 with: name: test-reports path: | reports/ !reports/**/*.tmp # Upload with custom retention and compression - name: Upload with Options uses: actions/upload-artifact@v7 with: name: optimized-artifact path: build/ retention-days: 7 compression-level: 9 # Maximum compression if-no-files-found: error # Fail if no files found ``` -------------------------------- ### Create a new git branch Source: https://github.com/actions/upload-artifact/blob/main/CONTRIBUTING.md Use this command to create and switch to a new branch for your changes. ```bash git checkout -b my-branch-name ``` -------------------------------- ### Merge multiple artifacts in v3 Source: https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md Demonstrates the v3 approach of uploading multiple files to the same artifact name across different jobs. ```yaml jobs: upload: strategy: matrix: runs-on: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.runs-on }} steps: - name: Create a File run: echo "hello from ${{ matrix.runs-on }}" > file-${{ matrix.runs-on }}.txt - name: Upload Artifact uses: actions/upload-artifact@v3 with: name: all-my-files # NOTE: same artifact name path: file-${{ matrix.runs-on }}.txt ``` -------------------------------- ### Upload Artifact Using Environment Variable for Path Source: https://github.com/actions/upload-artifact/blob/main/README.md Set environment variables in a previous step and reference them using `${{ env.variable_name }}` in the 'path' input for dynamic artifact uploads. Ensure the environment variable is correctly exported using `$GITHUB_ENV`. ```yaml steps: - run: | mkdir testing echo "This is a file to upload" > testing/file.txt echo "artifactPath=testing/file.txt" >> $GITHUB_ENV - uses: actions/upload-artifact@v7 with: name: artifact path: ${{ env.artifactPath }} # this will resolve to testing/file.txt at runtime ``` -------------------------------- ### Upload an Individual File (Unzipped) Source: https://github.com/actions/upload-artifact/blob/main/README.md Uploads a single file without zipping. The `archive: false` option is used, and the `name` parameter is ignored, using the file name as the artifact name. ```yaml steps: - run: mkdir -p path/to/artifact - run: echo hello > path/to/artifact/world.txt - uses: actions/upload-artifact@v7 with: path: path/to/artifact/world.txt archive: false ``` -------------------------------- ### Upload Unzipped Artifacts Source: https://context7.com/actions/upload-artifact/llms.txt Shows how to disable archiving to upload files as-is, which is useful for preserving file formats or permissions. ```yaml name: Upload Unzipped Artifact on: [push] jobs: upload: runs-on: ubuntu-latest steps: - name: Create a large binary file run: dd if=/dev/urandom of=my-binary bs=1M count=100 - name: Upload Unzipped Binary uses: actions/upload-artifact@v7 with: path: my-binary archive: false # Upload without zipping # Useful for preserving file permissions with tar - name: Create files with permissions run: | mkdir mydir echo "executable script" > mydir/run.sh chmod +x mydir/run.sh tar -cvf my_files.tar mydir/ - name: Upload Tar (preserves permissions) uses: actions/upload-artifact@v7 with: path: my_files.tar archive: false ``` -------------------------------- ### Upload Artifact with Implicit Naming (Potential Conflict) Source: https://github.com/actions/upload-artifact/blob/main/README.md Demonstrates uploading artifacts with implicit naming. Uploading to the same artifact name across multiple jobs is not supported and will result in a conflict error. ```yaml - run: echo hi > world.txt - uses: actions/upload-artifact@v7 with: # implicitly named as 'artifact' path: world.txt - run: echo howdy > extra-file.txt - uses: actions/upload-artifact@v7 with: # also implicitly named as 'artifact', will fail here! ``` -------------------------------- ### Configure retention and compression level Source: https://github.com/actions/upload-artifact/blob/main/merge/README.md Control the artifact's retention period in days using 'retention-days' and adjust the compression level (speed vs. size trade-off) with 'compression-level'. ```yaml jobs: # ... ... merge: runs-on: ubuntu-latest needs: upload steps: - name: Merge Artifacts uses: actions/upload-artifact/merge@v4 with: retention-days: 1 compression-level: 9 ``` -------------------------------- ### Upload Artifact with Maximum Compression Source: https://context7.com/actions/upload-artifact/llms.txt Use `compression-level: 9` for maximum compression, which is most effective for repetitive or text-heavy content. ```yaml - name: Upload with Maximum Compression uses: actions/upload-artifact@v7 with: name: text-max-compression path: large-text.txt compression-level: 9 ``` -------------------------------- ### Upload an Entire Directory Source: https://github.com/actions/upload-artifact/blob/main/README.md Uploads all contents of a specified directory as a zipped artifact. The directory path can be specified with or without a trailing slash. ```yaml - uses: actions/upload-artifact@v7 with: name: my-artifact path: path/to/artifact/ # or path/to/artifact ``` -------------------------------- ### Upload an Individual File (Zipped) Source: https://github.com/actions/upload-artifact/blob/main/README.md Uploads a single file as a zipped artifact. Ensure the file exists before uploading. ```yaml steps: - run: mkdir -p path/to/artifact - run: echo hello > path/to/artifact/world.txt - uses: actions/upload-artifact@v7 with: name: my-artifact path: path/to/artifact/world.txt ``` -------------------------------- ### Upload using a Wildcard Pattern Source: https://github.com/actions/upload-artifact/blob/main/README.md Uploads files matching a wildcard pattern. The `@actions/glob` package is used internally for pattern matching. ```yaml - uses: actions/upload-artifact@v7 with: name: my-artifact path: path/**/[abc]rtifac?/* ``` -------------------------------- ### Artifact structure visualization Source: https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md Visual representation of the file structure resulting from the v3 merge process. ```text . ∟ file-ubuntu-latest.txt ∟ file-macos-latest.txt ∟ file-windows-latest.txt ``` -------------------------------- ### Multiple Uploads to Different Artifacts (v4) Source: https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md In v4, artifacts are immutable. To achieve similar results to v3's multiple uploads, each upload must have a unique name. The 'pattern' input filters downloads, and 'merge-multiple: true' combines them into one directory. ```yaml jobs: upload: strategy: matrix: runs-on: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.runs-on }} steps: - name: Create a File run: echo "hello from ${{ matrix.runs-on }}" > file-${{ matrix.runs-on }}.txt - name: Upload Artifact uses: actions/upload-artifact@v4 with: name: my-artifact-${{ matrix.runs-on }} path: file-${{ matrix.runs-on }}.txt download: needs: upload runs-on: ubuntu-latest steps: - name: Download All Artifacts uses: actions/download-artifact@v4 with: path: my-artifact pattern: my-artifact-* merge-multiple: true - run: ls -R my-artifact ``` -------------------------------- ### Upload using Multiple Paths and Exclusions Source: https://github.com/actions/upload-artifact/blob/main/README.md Uploads multiple paths and excludes specific files using glob patterns. Excluded paths do not affect the directory structure. ```yaml - uses: actions/upload-artifact@v7 with: name: my-artifact path: | path/output/bin/ path/output/test-results !path/**/*.tmp ``` -------------------------------- ### Create Highly Compressible Text File Source: https://context7.com/actions/upload-artifact/llms.txt This script creates a large text file by repeatedly appending a string, generating content that is highly compressible for testing maximum compression. ```bash - name: Create highly compressible file run: | for i in {1..100000}; do echo "repeated text content" >> large-text.txt; done ``` -------------------------------- ### Upload Matrix Build Artifacts Source: https://context7.com/actions/upload-artifact/llms.txt Use matrix variables in the artifact name to ensure unique naming for parallel jobs. ```yaml name: Matrix Build with Artifacts on: [push] jobs: build: strategy: matrix: os: [ubuntu-latest, windows-latest, macos-latest] node: [18, 20, 22] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} - name: Build run: | mkdir dist echo "Built on ${{ matrix.os }} with Node ${{ matrix.node }}" > dist/build-info.txt - name: Upload Build Artifact uses: actions/upload-artifact@v7 with: name: build-${{ matrix.os }}-node${{ matrix.node }} path: dist/ retention-days: 5 ``` -------------------------------- ### Migrate artifact merging to v4 Source: https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md Shows the diff for migrating from v3 to v4, utilizing the new merge action to combine artifacts. ```diff jobs: upload: strategy: matrix: runs-on: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.runs-on }} steps: - name: Create a File run: echo "hello from ${{ matrix.runs-on }}" > file-${{ matrix.runs-on }}.txt - name: Upload Artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: - name: all-my-files + name: my-artifact-${{ matrix.runs-on }} path: file-${{ matrix.runs-on }}.txt + merge: + runs-on: ubuntu-latest + needs: upload + steps: + - name: Merge Artifacts + uses: actions/upload-artifact/merge@v4 + with: + name: all-my-files + pattern: my-artifact-* ``` -------------------------------- ### Upload Artifact with Default Compression Source: https://context7.com/actions/upload-artifact/llms.txt The default `compression-level` is 6, providing a balanced approach between upload speed and artifact size. This is suitable for general use cases. ```yaml - name: Upload with Default Compression uses: actions/upload-artifact@v7 with: name: balanced-compression path: large-text.txt # compression-level defaults to 6 ``` -------------------------------- ### Upload Artifact with GitHub Workspace Path Source: https://github.com/actions/upload-artifact/blob/main/README.md Employ GitHub Actions context expressions, such as `${{ github.workspace }}`, to dynamically specify artifact paths, enabling dynamic file generation and upload. ```yaml env: name: my-artifact steps: - run: | mkdir -p ${{ github.workspace }}/artifact echo hello > ${{ github.workspace }}/artifact/world.txt - uses: actions/upload-artifact@v7 with: name: ${{ env.name }}-name path: ${{ github.workspace }}/artifact/**/* ``` -------------------------------- ### Upload Artifact with Maximum Compression Source: https://github.com/actions/upload-artifact/blob/main/README.md Set compression-level to 9 for data that compresses well, such as plaintext or code, to save space. This increases CPU usage and upload time. ```yaml - name: Make a file with a lot of repeated text run: | for i in {1..100000}; do echo -n 'foobar' >> foobar.txt; done - uses: actions/upload-artifact@v7 with: name: my-artifact path: foobar.txt compression-level: 9 # maximum compression ``` -------------------------------- ### Merge Artifacts with upload-artifact/merge Source: https://context7.com/actions/upload-artifact/llms.txt Combines multiple artifacts into a single artifact using pattern matching. Supports optional deletion of source artifacts and directory separation. ```yaml name: Merge Artifacts Example on: [push] jobs: build: strategy: matrix: component: [frontend, backend, shared] runs-on: ubuntu-latest steps: - name: Build component run: | mkdir dist echo "Built ${{ matrix.component }}" > dist/${{ matrix.component }}.js - name: Upload Component Artifact uses: actions/upload-artifact@v4 with: name: build-${{ matrix.component }} path: dist/ merge: needs: build runs-on: ubuntu-latest steps: # Merge all build-* artifacts into one - name: Merge All Build Artifacts uses: actions/upload-artifact/merge@v4 with: name: complete-build pattern: build-* delete-merged: true # Remove individual artifacts after merge # Alternative: Merge with separate directories to avoid file conflicts - name: Merge with Directories uses: actions/upload-artifact/merge@v4 with: name: complete-build-separated pattern: build-* separate-directories: true # Each artifact in its own subdirectory retention-days: 30 compression-level: 9 ``` -------------------------------- ### Upload hidden files in v4 Source: https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md Shows the diff for enabling hidden file uploads in v4 using the include-hidden-files input. ```diff jobs: upload: runs-on: ubuntu-latest steps: - name: Create a Hidden File run: echo "hello from a hidden file" > .hidden-file.txt - name: Upload Artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: path: .hidden-file.txt + include-hidden-files: true ``` -------------------------------- ### Update dependency cache Source: https://github.com/actions/upload-artifact/blob/main/CONTRIBUTING.md Use the Licensed tool to update the dependency cache after modifying production dependencies. ```bash licensed cache ``` -------------------------------- ### Access Artifact Outputs Source: https://context7.com/actions/upload-artifact/llms.txt Utilize artifact-id, artifact-url, and artifact-digest outputs in subsequent steps or jobs. ```yaml name: Use Artifact Outputs on: [push] jobs: build: runs-on: ubuntu-latest outputs: artifact-id: ${{ steps.upload.outputs.artifact-id }} artifact-url: ${{ steps.upload.outputs.artifact-url }} steps: - name: Build run: | mkdir output echo "Build complete" > output/result.txt - name: Upload Artifact id: upload uses: actions/upload-artifact@v7 with: name: build-result path: output/ - name: Display Artifact Info run: | echo "Artifact ID: ${{ steps.upload.outputs.artifact-id }}" echo "Artifact URL: ${{ steps.upload.outputs.artifact-url }}" echo "Artifact Digest: ${{ steps.upload.outputs.artifact-digest }}" notify: needs: build runs-on: ubuntu-latest steps: - name: Post Artifact Link run: | echo "Build artifact available at: ${{ needs.build.outputs.artifact-url }}" echo "Artifact ID for API access: ${{ needs.build.outputs.artifact-id }}" ``` -------------------------------- ### Preserve File Permissions with Tar Source: https://github.com/actions/upload-artifact/blob/main/README.md Upload files while preserving their original permissions by archiving them into a tarball before uploading. Set `archive: false` to upload the tarball directly. ```yaml - name: 'Tar files' run: tar -cvf my_files.tar /path/to/my/directory - name: 'Upload Artifact' uses: actions/upload-artifact@v7 with: path: my_files.tar archive: false ``` -------------------------------- ### POST @actions/upload-artifact/merge Source: https://github.com/actions/upload-artifact/blob/main/merge/README.md Merges multiple artifacts created with upload-artifact@v4+ into a single artifact. ```APIDOC ## POST @actions/upload-artifact/merge ### Description Merges multiple artifacts into a single artifact by downloading them to a temporary directory and re-uploading them. ### Parameters #### Request Body - **name** (string) - Optional - The name of the artifact that the artifacts will be merged into. Default is 'merged-artifacts'. - **pattern** (string) - Optional - A glob pattern matching the artifacts that should be merged. Default is '*'. - **separate-directories** (boolean) - Optional - If true, the artifacts will be merged into separate directories. Default is 'false'. - **delete-merged** (boolean) - Optional - If true, the artifacts that were merged will be deleted. Default is 'false'. - **retention-days** (integer) - Optional - Duration after which artifact will expire in days (1-90). Default is repository settings. - **compression-level** (integer) - Optional - The level of compression for Zlib (0-9). Default is '6'. ### Request Example ```yaml - uses: actions/upload-artifact/merge@v4 with: name: my-merged-artifact pattern: my-artifact-* separate-directories: false delete-merged: true ``` ### Response #### Success Response (200) - **artifact-id** (string) - GitHub ID of an Artifact. - **artifact-url** (string) - URL to download an Artifact. - **artifact-digest** (string) - SHA-256 digest of an Artifact. ``` -------------------------------- ### Matrix Strategy for Unique Artifact Naming Source: https://github.com/actions/upload-artifact/blob/main/README.md Utilize matrix strategy to generate unique artifact names by incorporating matrix variables, preventing naming conflicts in parallel jobs. ```yaml jobs: upload: name: Generate Build Artifacts strategy: matrix: os: [ubuntu-latest, windows-latest] version: [a, b, c] runs-on: ${{ matrix.os }} steps: - name: Build run: ./some-script --version=${{ matrix.version }} > my-binary - name: Upload uses: actions/upload-artifact@v7 with: name: binary-${{ matrix.os }}-${{ matrix.version }} path: my-binary ``` -------------------------------- ### Prefix directories in merged artifact Source: https://github.com/actions/upload-artifact/blob/main/merge/README.md Use the 'separate-directories' input set to 'true' to prefix extracted files with directories named after their original artifacts. This prevents file name collisions. ```yaml jobs: # ... ... merge: runs-on: ubuntu-latest needs: upload steps: - name: Merge Artifacts uses: actions/upload-artifact/merge@v4 with: separate-directories: true ``` -------------------------------- ### Overwrite Existing Artifacts Source: https://context7.com/actions/upload-artifact/llms.txt Set overwrite: true to replace an existing artifact with the same name. ```yaml name: Overwrite Artifact Example on: [push] jobs: initial-upload: runs-on: ubuntu-latest steps: - name: Create initial file run: echo "Initial content" > myfile.txt - name: Upload Initial Artifact uses: actions/upload-artifact@v7 with: name: my-artifact path: myfile.txt update-artifact: needs: initial-upload runs-on: ubuntu-latest steps: - name: Create updated file run: echo "Updated content" > myfile.txt - name: Overwrite Artifact uses: actions/upload-artifact@v7 with: name: my-artifact path: myfile.txt overwrite: true # Replaces the existing artifact ``` -------------------------------- ### Overwrite an Existing Artifact Source: https://github.com/actions/upload-artifact/blob/main/README.md Completely replace an existing artifact with new content. Note that this action assigns a new ID to the artifact. ```yaml jobs: upload: runs-on: ubuntu-latest steps: - name: Create a file run: echo "hello world" > my-file.txt - name: Upload Artifact uses: actions/upload-artifact@v7 with: name: my-artifact # NOTE: same artifact name path: my-file.txt upload-again: needs: upload runs-on: ubuntu-latest steps: - name: Create a different file run: echo "goodbye world" > my-file.txt - name: Upload Artifact uses: actions/upload-artifact@v7 with: name: my-artifact # NOTE: same artifact name path: my-file.txt overwrite: true ``` -------------------------------- ### Specify Artifact Retention Period Source: https://github.com/actions/upload-artifact/blob/main/README.md Set a custom retention period for an artifact, between 1 and 90 days. The default is 90 days. ```yaml - name: Upload Artifact uses: actions/upload-artifact@v7 with: name: my-artifact path: my_file.txt retention-days: 5 ``` -------------------------------- ### Change artifact name and filter artifacts Source: https://github.com/actions/upload-artifact/blob/main/merge/README.md Customize the name of the merged artifact and specify which artifacts to include using the 'name' and 'pattern' inputs. The 'pattern' input supports glob matching. ```yaml jobs: # ... ... merge: runs-on: ubuntu-latest needs: upload steps: - name: Merge Artifacts uses: actions/upload-artifact/merge@v4 with: name: my-amazing-merged-artifact pattern: my-artifact-* ``` -------------------------------- ### Combine all artifacts into a single artifact Source: https://github.com/actions/upload-artifact/blob/main/merge/README.md By default, this action merges all artifacts from a workflow run into a single artifact named 'merged-artifacts'. No additional inputs are required for this basic functionality. ```yaml jobs: # ... ... merge: runs-on: ubuntu-latest needs: upload steps: - name: Merge Artifacts uses: actions/upload-artifact/merge@v4 ``` -------------------------------- ### Overwriting Artifacts with New ID (v4) Source: https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md In v4, artifacts are immutable. To overwrite an artifact, use 'overwrite: true' which deletes the existing artifact and creates a new one with a different ID. This ensures data integrity by creating a new artifact rather than modifying an existing one. ```yaml jobs: upload: runs-on: ubuntu-latest steps: - name: Create a file run: echo "hello world" > my-file.txt - name: Upload Artifact uses: actions/upload-artifact@v4 with: name: my-artifact # NOTE: same artifact name path: my-file.txt upload-again: needs: upload runs-on: ubuntu-latest steps: - name: Create a different file run: echo "goodbye world" > my-file.txt - name: Upload Artifact uses: actions/upload-artifact@v4 with: name: my-artifact # NOTE: same artifact name path: my-file.txt overwrite: true ``` -------------------------------- ### Access Artifact ID Between Steps Source: https://github.com/actions/upload-artifact/blob/main/README.md Retrieve the artifact ID after a successful upload to use in subsequent steps. This ID can be used with Artifact REST APIs. ```yaml - uses: actions/upload-artifact@v7 id: artifact-upload-step with: name: my-artifact path: path/to/artifact/content/ - name: Output artifact ID run: echo 'Artifact ID is ${{ steps.artifact-upload-step.outputs.artifact-id }}' ``` -------------------------------- ### Delete artifacts after merge Source: https://github.com/actions/upload-artifact/blob/main/merge/README.md Automatically delete the original artifacts after they have been successfully merged into the new artifact by setting the 'delete-merged' input to 'true'. ```yaml jobs: # ... ... merge: runs-on: ubuntu-latest needs: upload steps: - name: Merge Artifacts uses: actions/upload-artifact/merge@v4 with: delete-merged: true ``` -------------------------------- ### Access Artifact ID Between Jobs Source: https://github.com/actions/upload-artifact/blob/main/README.md Share an artifact ID between different jobs in a workflow. This allows subsequent jobs to reference artifacts uploaded in previous jobs. ```yaml jobs: job1: runs-on: ubuntu-latest outputs: output1: ${{ steps.artifact-upload-step.outputs.artifact-id }} steps: - uses: actions/upload-artifact@v7 id: artifact-upload-step with: name: my-artifact path: path/to/artifact/content/ job2: runs-on: ubuntu-latest needs: job1 steps: - env: OUTPUT1: ${{needs.job1.outputs.output1}} run: echo "Artifact ID from previous job is $OUTPUT1" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.