My workflow has automatic packaging and upload steps that package build artifacts and upload them to the workflow page. I also manually create releases.
I would like to do the following:
when I push to the tag that was created with a given release,
I would like to upload the zipped artifact file to that release, so users can download
the artifact. Any tips on how to do this ?
Here is my build yaml file.
Thanks!
Turns out it's dead simple to do this:
- name: upload binaries to release
uses: softprops/action-gh-release#v1
if: ${{startsWith(github.ref, 'refs/tags/') }}
with:
files: build/FOO.zip
It seems the action (softprops/action-gh-release#v1) mentioned also creates a release. But there is a much simpelere way upload an artifact to a release without the need of introducing action. The gh cli which is by default available on a GitHub hosted runners can upload the artifact for you.
assets:
name: upload assets
runs-on: ubuntu-latest
permissions:
contents: write # release changes require contents write
steps:
- uses: actions/checkout#v3
- name: Upload Release Asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run:
gh release upload <release_tag> <a_file>
Checkout full release example here.
Related
We succesfully use the Plesk / Github integration that deploys our developers pushes from github to our plesk stage web server using the Webhooks to have Pleask get the latest version. That works splendidly. What we try to establish additionally is auto compile the SCSS source and submit the resulting css as well to our stage web server. We have added an action to the workflow but how would the compiled products end up on our stage webserver. I'm unsure if the timing is right. Will the actinos be performed before deployment?
This is the yaml:
on:
push:
branches:
- stage
jobs:
build_css:
runs-on: ubuntu-latest
steps:
- name: Checkout source Git branch
uses: actions/checkout#v2
with:
ref: stage
fetch-depth: 10
submodules: true
- name: Make destination directory for compiled CSS
run: mkdir -vp /tmp/theme/assets/
- name: Compile CSS from SCSS files
uses: gha-utilities/sass-build#v0.4.11
with:
source: assets/src/main.scss
destination: /tmp/theme/assets/
- name: Move compiled CSS to path within stage branch
run: mv /tmp/theme/assets assets/
Im running a job that creates a folder dist and another job that depends on the first one to be completed successfully to upload the dist folder. However I'm getting an error when uploading saying the directory doesn't exist, while it works to create the folder locally and push it to github. I don't want to push the folder to my repo is there a way to work?
name: Build Artifcats and Upload To Azure Blob Storage
on:
push:
branches:
- main
jobs:
build_on_win:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#master
with:
node-version: 14.2.0
Running Scripts**.........
upload:
runs-on: ubuntu-latest
needs: build_on_win (Notice here I'm waiting for the artifacts to be built)
steps:
- uses: actions/checkout#v2
- uses: bacongobbler/azure-blob-storage-upload#v1.2.0
with:
source_dir: ./solutions/app/dist
container_name: 'app/latest'
connection_string: .......
sync: true
Folders (and files) aren't shared between jobs.
To achieve what you want, you will need to upload the dist directory as an artifact (using the upload action then download this artifact on the second job with the download action before performing the action you want on the second job.
You can find more information on the GHA official documentation.
I've forked a project:
and I'm setting up a CI definition on non master branches with these final steps:
- name: Zip the release
uses: papeloto/action-zip#v1
with:
files: README.md LICENSE *.dll nfive.yml nfive.lock fxmanifest.lua index.html config/
dest: ${{ github.workspace }}\nfive.zip
- name: Attach Zip as build artifact
uses: actions/upload-artifact#v1
with:
name: nfive
path: ${{ github.workspace }}\nfive.zip
Why does github.workspace point to the original repository NFive\NFive?
So, if run echo ${{ github.workspace }} it definitely shows the parent repository, but to make this even more difficult if I change directory to my organisation name and forked repository name I get this:
which is the output of these steps:
- run: echo ${{ github.workspace }}
- name: Move files to artifact folder
shell: pwsh
run: |
cd D:\a\HTB-5M\NFive
mkdir Build
Move-Item -Path README.md,LICENSE,*.dll,nfive.yml,nfive.lock,fxmanifest.lua,index.html,config -Destination Build
I don't have access to the parent path because I'm not a contributor, which is why I forked in the first place, so why does Github assume github.workspace should map to the parent?
=== Udate ===
So I reforked to my user account rather than the organisation I used and added a workflow step to just display the github.workspace variable and it definitely says the parent workspace D:\a\NFive\NFive
I tried changing the path in the nfive.yml
Same outcome
Deleting the nfive.yml doesn't change anything. I think the nfive.yml is actually used in the CI / CD pipelines the original authors configured on appveyor so it isn't going to affect anything here.
It isn't pointing to the fork parent repo, it's because the github.workspace variable follows this format: /home/runner/work/my-repo-name/my-repo-name.
That's the reason why NFive appears twice, it's NOT refering to NFive username / organization, but twice to the NFive repository name.
This is explained on the github documentation about default environment variables
I forked the repository as well and I don't get any error when running this workflow.
Here is the workflow run output with the generated .zip file artifact.
I want to automate the build and publishing of the docs of an open source typescript project hosted on Github.
I tried TypeDoc and the generated docs folder is 23Mo. I don't want to commit it in the project's repo.
Ideally, on each release, I would like to use github actions to:
generate the docs
push that generated docs folder to its own github repo.
Currently I added a npm script to generate the docs: docs: typedoc --out docs src and here is the starting point of my github action file:
name: Docs
on:
release:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v1
- name: Use Node.js
uses: actions/setup-node#v1
with:
node-version: 12
- name: Generate docs
run: |
npm ci
npm run docs
From this action, how can I commit and push this generated directory to its own repo on github?
(Maybe there is a more conventional way to do that. Let me know)
If you want to commit and push changes, you can refer to some actions in the Github's marketplace like github-push or push changes to see if they are fitting your situation. Also, you can write your own script to call Github's API, e.g. I use Pygithub to call Github's APT to help me generate changelog and update the file in the repo.
You can use the github-action-push-to-another-repository action for this purpose:
- name: Pushes to another repository
uses: cpina/github-action-push-to-another-repository#main
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
with:
source-directory: <directory-where-the-dist-is-generated>
destination-github-username: <github-username>
destination-repository-name: <github-repository-name>
user-email: <github-email>
target-branch: <main/master>
Can I trigger a new workflow from another workflow?
I'm trying to run a workflow after the first workflow has pushed a new release and it seems to ignore it.
Found the answer here:
An action in a workflow run can't trigger a new workflow run. For example, if an action pushes code using the repository's GITHUB_TOKEN, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.
EDIT:
The quote above might be confusing. When I add a Personal Access Token (PAT) to the checkout action with repo permissions granted (and not repository's GITHUB_TOKEN), the following commands DO trigger other workflows:
- name: Checkout Repo
uses: actions/checkout#v2
with:
token: ${{ secrets.PAT_TOKEN }}
(In my case, running semnatic-release after this checkout, which creates a new release with a new tag - did trigger another workflow that runs only if a tag was created)
As described here, you can trigger another workflow using the workflow_run event.
For example we could think of two workflow definitions like this (the only prerequisite is, that both reside in the same repository - but I'am sure, there's also an event for other repos as well):
release.yml
name: CI release
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Release artifact
run: ...
do-something-different.yml
name: Do anything after the release of the first workflow
on:
workflow_run:
workflows: ["CI release"]
types:
- completed
jobs:
notify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Do something
run: ...
A crucial point here is that the name: CI release definition of the first yaml file must exactly match the workflow_run: workflows: ["CI release"] definition in the second yaml file. Another point is that this approach needs to be done on the default branch (which is mostly main or master) as the docs state:
Note: This event will only trigger a workflow run if the workflow file
is on the default branch.
If you don't want to use a general Personal Access Token (which has access to all of your repos), you can generate a dedicated SSH keypair for this purpose and add it to the repository as a Deploy Key. This is done as follows:
Generate an SSH keypair:
ssh-keygen -N "" -f deploy_key -C "github-actions"
Add the private key (generated file deploy_key) as an encryped secret, e.g. COMMIT_KEY to the GitHub project.
Add the public key (generated file deploy_key.pub) as a deploy key with write access to the GitHub project. Tick the Allow write access checkbox.
When checking out the source code in your workflow, add the SSH key:
- name: Checkout
uses: actions/checkout#v3
with:
ssh-key: "${{secrets.COMMIT_KEY}}"
Subsequent push actions in the same workflow will then trigger any configured GitHub workflow as if they were pushed manually.