Reputation: 64
I created this GitHub Actions script to unpack any tar files that might be uploaded to a repository, but I am having some problems with it
The workflow does not trigger on push (I have tried both with tar and non-tar files)
When I manually trigger it, it does not unpack anything and gives me no errors
It does give me a warning
Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: actions/setup-node@v3. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.
I read the post and I (hope) I updated the file accordingly, but the error persists.
name: Unpack tgz Files
on:
push:
paths:
- '*.tgz'
pull_request:
paths:
- '*.tgz'
workflow_dispatch: # Allow manual triggering of the workflow
jobs:
unpack:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Create /src directory if it doesn't exist
run: mkdir -p src
- name: List tgz files
run: |
echo "Listing tgz files in root directory:"
ls *.tgz || echo "No tgz files found"
- name: Extract tgz files
run: |
for tgzfile in *.tgz; do
if [ -f "$tgzfile" ]; then
dirname=$(basename "$tgzfile" .tgz)
mkdir -p "src/$dirname"
tar -xf "$tgzfile" -C "src/$dirname"
echo "Unpacked $tgzfile into src/$dirname"
fi
done
I have also looked at these:
EDIT:
The output looks like this, but the /src
folder is never created nor the file unzipped. I have also updated the code to use v4
EDIT 2: I updated the code to (hopefully) check for .tzg files instead of .tar files (dumb mistake), but the src directory is still not created nor is the .tgz file unpacked
Upvotes: 1
Views: 295
Reputation: 669
First you have to make sure that the pattern(s) match the file extension you're using :
paths:
- '**.tar'
- '**.tgz'
You can match several patterns this way.
For the Node.js 16 warning, you can update to the v4 version of the checkout action.
Lastly, regarding the exctracted files : your workflow runs in a separate environment, that's why at the start you have to checkout the code : it doesn't exist yet. You can create folders, files, and run all kinds of programs / script but at the end nothing is saved.
If you want to extract the files from the archive and push them to your repo, you can first use your "Extract tgz files" step, then use git add [your files], git commit and then git push origin [your branch].
You can also use the upload-artifact action to upload your folder to Github :
- name: Upload folder
uses: actions/upload-artifact@v4
with:
name: Extracted archive
path: src/
Upvotes: 1