I'm making an action that runs a script that deletes some files from a github repository and I want to create a pull request with those changes.
So far the structure is like this:
#myactionscript.yml
name: test
on: push
jobs:
delete:
runs-on: ubuntu-latest
steps:
#setup steps
...
- name: delete files
run: |
#script that deletes files
- name: Create Pull Request
uses: peter-evans/create-pull-request#v4.0.4
I published the action so I could test it on a private repo. If I print the folder contents, I can see that the file deletion script is working, but the pull request is not being created. However, it does work when I use it externally on my private repo, like this:
#privaterepoworkflow.yml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: File deletion
uses: myuser/deletion-action#test5
- name: Create Pull Request
uses: peter-evans/create-pull-request#v4.0.4
This creates the Pull Request with the deleted files, but it requires me to add the code snippet to my private repo, so for every repository that I wanna run this action on, I will also have to paste the Create Pull Request snippet. Is there any way to make it so the Pull Request is created while adding this snippet only in the delete action itself?
Related
I am trying to use actions to post a comment on a PR if a file has changed but my action is unable to see the changes.
jobs:
check:
runs-on: self-hosted
permissions:
pull-requests: write
steps:
- uses: actions/checkout#v2
with:
fetch-depth: 2
- name: Get all changed files and echo alert
env:
GITHUB_TOKEN: *******************
run: |
git diff --name-status
or if I change it to git status it outputs a message saying no changes working tree is clean, but I know one file has changed.
I tried using v1 instead of v2 but that doesn't work either.
Does anyone have any ideas on what i am doing wrong or how I can get this working?
Checkout is just "checking out" clean repository state for a given commit or PR.
If you expect to get changes files from PR, you can do it by using external actions, for examples:
- name: Get changed files using defaults
id: changed-files
uses: tj-actions/changed-files#v32
- name: List all added files
run: |
for file in ${{ steps.changed-files.outputs. modified_files }}; do
echo "$file was modified."
done
Use Github contexts: Learn GitHub Actions Contexts
Here is the command you probably need:
git diff --name-only ${{ github.event.after }} ${{ github.event.before }}
Also, you could affect the whole action by setting paths at the beginning of an action:
name: Action #1
on:
push:
branches:
- main
paths:
- <folder>/** // action will be triggered by push to the main branch AND when there are changed files in <folder>
pull_request:
branches:
- main
paths:
- <folder>/*.js // action will be triggered only on pull-requests AND when any .js files in <folder> have been changed
Is there a way to tell GitHub to automatically create a pull request from an API providing JSON content and merge it into my project?
I want to:
Edit files on a platform (I control the platform) using my own production editors/tools.
Have GitHub request it (REST), then create a PR or a commit, so people can collaborate on it with forks/GitHub project management.
Push from GitHub back to the platform for publishing.
3 is no problem, but 2 I can't find documentation for if it's even possible.
name: Manual workflow
on:
workflow_dispatch:
jobs:
makefiles:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout#v2
- name: Getting
uses: fjogeleit/http-request-action#master
id: myRequest
with:
url: 'https://domain/api/file'
method: 'GET'
- name: Show File
run: echo ${{ steps.myRequest.outputs.response }}
- name: Create A File
uses: 1arp/create-a-file-action#0.2
with:
path: 'src'
file: 'foo.bar'
content: ${{steps.myRequest.outputs.response}}
- name: final commit
uses: zwaldowski/git-commit-action#v1
id: git_commit
- name: show
run: echo "${{ steps.git_commit.outputs.sha }}"
I am trying to upload a repo to server via ftp on push to master branch. I have it set up and working. However in the repo there is a folder /public. I only want to upload the files in this folder to the server. Not other files or the folder itself. I have tried to set up a working directory for the job but this doesn't seem to do the trick.. any ideas?
on:
push:
branches:
- master
name: 🚀 Deploy website on push
jobs:
ftp-web-deploy:
name: 🎉 Deploy
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./public
steps:
- name: 🚚 Get latest code
uses: actions/checkout#v2.4.0
working-directory: ./public
with:
fetch-depth: 2
- name: 📂 Sync files
uses: SamKirkland/FTP-Deploy-Action#4.2.0
with:
server: ****
username: ****
password: ${{ secrets.prod_ftp_password }}
server-dir: public_html/
Checking out only one directory is not possible, but has been requested in the actions/checkout repository before: https://github.com/actions/checkout/issues/483
There's an action to check out specific files, but I haven't tried it and I'm not sure if it does what you want: https://github.com/marketplace/actions/checkout-files
You might want to ask yourself why you're trying to limit the number of files transferred. Is it because you're concerned about traffic? Or because of the input expected in the subsequent action?
If it's the latter, you could also manually "fix" the structure by running some mv and rm commands.
I am trying to use Github actions on the Push event to my master branch for running a wget command to mirror a website and download its contents as static files and then zip them together for uploading to an s3 bucket. Here is my test_events.yml file stored under .github/workflows in my git repo:
name: create a mirror of website and zip the saved contents
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
mirror-website:
name: mirrors the website
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout#v2
- name: wget
uses: wei/wget#v1
with:
args: -O logfile.txt -P ./actions/ https://adappt.co.uk
zip-files:
name: Zips the Saved file
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout#v2
- name: Prepares a zip file
uses: montudor/action-zip#v1.0.0
with:
args: zip -qq -r adappt_co_uk.zip . -i /actions/adappt.co.uk
Problem is whenever I push a change in my repo, the action gets triggered and gets completed without errors. But it does not save the web files to the given location, and hence, doesn't perform the zip operation as well.
What am I doing wrong here? Is there any other way apart from using wget?
I'm using Github actions with two workflows: CI and CD. The CI workflow is triggered for new tags like v1.1.1 and pull requests to develop and hotfix branches.
name: CI
on:
push:
tags: v[1-9]+.[0-9]+.[0-9]+
pull_request:
branches: [develop, hotfix*]
The CD workflow is triggered when the previous workflow (CI) is completed.
name: CD
on:
workflow_run:
workflows: ['CI']
push:
tags: v[1-9]+.[0-9]+.[0-9]+
types:
- completed
Currently, my goal is to generate packages (Docker images) based on the name of the new tag. I'm trying to read the new tag name in the CD workflow using the action dawidd6/action-get-tag#v1:
- name: Get tag
id: tag
uses: dawidd6/action-get-tag#v1
- name: Use tag
run: echo ${{steps.tag.outputs.tag}}
But I'm getting the following error:
Run dawidd6/action-get-tag#v1
env:
IMAGE_NAME: open-tuna-api
Error: Not a tag ref (refs/heads/master)
My question is: how to read the tag name in my CD workflow that is triggering after the CI workflow?
First of all, you can get the tag without using an action, with ${GITHUB_REF##*/}.
Sample test workflow:
name: Experiment
on:
push:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Debug
run: echo "Works. Tag is ${GITHUB_REF##*/}"
As for the chained workflows you mention - I am not sure it is possible to get the tag of the ancestor workflow, since the documentation mentions it is triggered on the default branch, and the last commit on that branch.