Do I need the pages-build-deployment Github Action, when I have another action for my Github Pages? - github

In the settings I've enabled Github Pages:
I have a Github Action which builds and deploy the page to the branch gh-pages.
name: Continuous Deployment
on:
push:
branches:
- master
schedule:
- cron: '0 0 * * *'
jobs:
build-and-deploy:
name: Build and deploy to Github Pages
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout#v3
- name: Use nodejs
uses: actions/setup-node#v3
with:
node-version: '16.x'
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Activate dependency cache
uses: actions/cache#v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Caching Gatsby
id: gatsby-cache-build
uses: actions/cache#v3
with:
path: |
public
.cache
key: ${{ runner.os }}-gatsby-build-cache-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-gatsby-build-cache-
- name: Build website
run: yarn build:with-prefix
env:
PATH_PREFIX: '/xyz'
SITE_URL: 'https://xyz.github.io/xyz'
CI: true
- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action#v4.3.3
with:
branch: gh-pages
folder: public
clean: true
Now there is another Github Action which seem to deploy my page to Github Actions (using Jakyll):
Now I have two questions, which I couldn't answer by searching the internet:
Do I need this other action pages-build-deployment?
If not, how can I disable it?
If yes, for what it's needed? Am I doing the same work twice?

Do I need this other action pages-build-deployment?
This is provided by GitHub automatically.
As discussed in JamesIves/github-pages-deploy-action #1073:
I think there's a lot of scope for confusion for users of this action, when pages build and deployment will also be running on every push and pushing pages assets.
I think it's impossible to really say right now what that looks like until GitHub announces what these actions intend to do in the long run.
As the post suggests, this is a necessary step that occurs after the push gets made, this was already occurring behind the scenes it just wasn't made visible.
So you can ignore it (and there is no obvious way to disable it).
As for doing the same work twice, the same post adds:
What used to happen is, behind the scenes, we used the github-pages[bot] to pull that branch down and deploy the content to the github-pages environment we create for you automatically.
Now this step happens transparently with this new Actions workflow.
The end goal we’re working on is, if you’d prefer to deploy to the pages environment directly (without committing the content to a gh-pages branch), you’ll be able to do that in your own workflow. This will remove the need for the second workflow that we trigger when you commit to the pages branch.
Context: Dec. 2021 "GitHub Pages: using GitHub Actions for builds and deployments for public repositories".
The initial benefit of this change is enabling you to see your build logs and any errors that may occur which has been a long standing issue for Pages users.
However, in the future this will enable us to give you the ability to fully customize your pages build and deployment workflow to use any static site generator you want without having to push the build output to a special branch of the repository.

Related

Automatically set the assignee on an issue using guthub actions

I am trying to add some automation to my github project (the project feature, not a repo). I added a project for my user which I use to manage all my issues. I created a github action that always assigns issues and PRs to this project so I always have an overview over all todos.
Now I want another action. My project uses 4 statuses:
Backlog
Selected for Development
In Progress
Done
I want to automatically assign a user to an issue when the issue is moved into status "In Progress". The assignee should be the current user (= ${{ github.actor }}). So far this works.
on:
issues:
types:
- opened
pull_request:
types:
- opened
permissions:
contents: read
issues: write
pull-requests: write
jobs:
add-to-project:
name: Add to project
runs-on: ubuntu-latest
steps:
- name: Add to project (issues and PRs)
uses: actions/add-to-project#main
with:
project-url: https://github.com/users/sebastian-sommerfeld-io/projects/1
github-token: ${{ secrets.GH_TOKEN_REPO_AND_PROJECT }}
assign-issue-to-user:
name: Assign to user
runs-on: ubuntu-latest
steps:
- name: Assign issue to user
uses: pozil/auto-assign-issue#v1
# https://github.com/marketplace/actions/auto-assign-issue
with:
assignees: ${{ github.actor }}
numOfAssignee: 1
allowSelfAssign: true
abortIfPreviousAssignees: true
Assigning the issue works (job assign-issue-to-user). But the assignee should only be set automatically, if the assignee field is empty (I do not want to override existing assignees) and if the issue is moved into the project status "In Progress". This if condition is the problem I cannot get my head around. The code above just always assigns the user when the issue is created. Regardless of any column change.

GitHub trigger on status change

I have a project (beta) called work tracker/planner.
When someone drags an issue from Ready to In Progress (for example), I want to change the status of that issue in a different project.
The second part I believe I can do using https://github.com/marketplace/actions/move-issues-to-column, thusly
jobs:
move-to-in-progress:
runs-on: ubuntu-latest
name: Move to In Progress Column
steps:
- name: Move to In Progress
uses: kin/gh-action-move-issue-to-column#1.0
with:
access-token: "#{{ secrets.GITHUB_TOKEN }}"
project-name: "DifferentProject"
target-column: "In Progress"
But how do I trigger the action, if the project_column event
does not occur for projects (beta)
according to GitHub.

How to make Github Actions workflow that is triggered by a pr comment to be reported in the pr checks

I have a called workflow that deploys the app to Heroku. It is triggered by a pr comment.
name: Preview App Deployment
on:
issue_comment:
types: [created]
jobs:
call-heroku-preview-app:
name: Deploy to Heroku
if: ${{ contains(github.event.comment.body, '/deploy') }}
uses: ./.github/workflows/heroku-preview-app.yml
However, it doesn't show up in the pr checks as it does for jobs that are triggered by
on:
pull_request:
types: [synchronize, opened, reopened, ready_for_review]
branches-ignore: [master, production]
which hurts visibility. Also, I'm planning to add another workflow triggered by a comment that runs unit and e2e tests. If the result won't be included in the Github checks it will be a problem.
So is it really impossible to include them there or I'm missing something?
PR Checks are attached to a commit, but when you're running a workflow on issue_comment what would the context be? Intuitively, comment in a PR is not a thing related to a commit.
In fact, when looking at ${{ github.sha }} inside a workflow triggered by issue_comment, the SHA is actually that of the default branch.
You could manually add a check using the Check Runs API.
However, when triggering this on issue_comment, you're going to have to replace the value github.sha with your own logic to identify the tip of the branch associated with the PR for which the comment was made.
- uses: actions/checkout#v3
- run: echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
- run: echo '{"name":"Test Check","head_sha":"${{ github.sha }}"}' | gh api /repos/{owner}/{repo}/check-runs --input -
Is there are reason you're only deploying when a comment is made? Why not deploy on every push? As you mentioned end-to-end tests as well, this would be another type of thing that is usually run automatically rather than when a person adds a comment.

Github Actions - trigger another action after one action is completed

I have one action (a yaml file) for deploying a docker image to Google Cloud Run.
I would like to receive Slack or Email messages informing the build and push results.
How could the message action be triggered after build action is completed?
Is it possible to get the result of the build action?
There are 2 options of doing this:
Use a second job inside the same workflow.yml together with the needs keyword
Create a separate notify.yml workflow that uses the workflow_run event as a trigger
1. Same workflow, separate job with needs keyword
In your workflow.yml file you simply define two jobs like this (leveraging the needs: build configuration in the second job):
name: CI build and notify
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Deploy Docker image to Google Cloud Run
run: ...
notify:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Notify Slack and send eMail
run: ...
As the docs state, the second notify job will only start if the first build job succeeded:
Identifies any jobs that must complete successfully before this job
will run.
Here's a screenshot of how this approach can look like practically from my own project (I have a second publish-snapshot job instead of your notify job - but the concept stays the same):
There's also a way to always let the notify job run, even if the build job failed. You have to enhance the needs with a if: always() configuration then.
2. Separate workflow, using the workflow_run event as a trigger
Using the workflow_run event as a trigger we end up having 2 separate GitHub Actions workflow yaml files:
build.yml
name: CI build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Deploy Docker image to Google Cloud Run
run: ...
notify.yml
name: CI notify
# Only trigger, when the build workflow succeeded
on:
workflow_run:
workflows: ["CI build"]
types:
- completed
jobs:
notify:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Notify Slack and send eMail
run: ...
A crucial point here is that the name: CI build definition of the first yaml file must exactly match the workflow_run: workflows: ["CI build"] 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.
Here's also a full example project using the 1st option if you're interested.
First, you are mixing terms here. According to GitHub Actions documentation a single YAML file is called a workflow (not an action) and consists of jobs. Jobs contain a sequence of steps (including actions) that are executed one after another. A particular workflow execution is called a run. Having that in mind lets go the questions.
How could the message workflow be triggered after build workflow is completed?
You can use GitHub API to trigger a webhook event called repository_dispatch (only for the base branch) or workflow_dispatch. This can be easily done using a dedicated Repository Dispach action in your build workflow.
Is it possible to get the result of the build workflow?
Yes, the result of the workflow run can be obtained using given GitHub API
But if you only want to send the build result notification of the currently executed workflow you don't need to create a separate workflow and trigger it from the parent. You can use dedicated Slack actions or e-mail actions.
you can try in step 2 the following directive:
needs: step-1-job-name
just after job name
The best method i've found for reusable workflows in the same repository is https://docs.github.com/en/actions/using-workflows/reusing-workflows
In the workflow you want to re-use (let's call it wf1):
# wf1.yml
on:
workflow_call:
In the workflow you want to call wf1 from (let's call this wf2)
# wf2.yml
jobs:
call-wf1:
uses: ./.github/workflows/wf1.yml
secrets: inherit
In order to get data from one workflow to another, check out https://docs.github.com/en/actions/using-workflows/reusing-workflows#using-outputs-from-a-reusable-workflow.
First, set up your reusable workflow to output the data:
name: Reusable workflow
on:
workflow_call:
# Map the workflow outputs to job outputs
outputs:
firstword:
description: "The first output string"
value: ${{ jobs.example_job.outputs.output1 }}
secondword:
description: "The second output string"
value: ${{ jobs.example_job.outputs.output2 }}
jobs:
example_job:
name: Generate output
runs-on: ubuntu-latest
# Map the job outputs to step outputs
outputs:
output1: ${{ steps.step1.outputs.firstword }}
output2: ${{ steps.step2.outputs.secondword }}
steps:
- id: step1
run: echo "::set-output name=firstword::hello"
- id: step2
run: echo "::set-output name=secondword::world"
Now use it in the calling workflow:
name: Call a reusable workflow and use its outputs
on:
workflow_dispatch:
jobs:
job1:
# local repo
# uses: .github/workflows/called-workflow.yml#v1
# other repo
uses: octo-org/example-repo/.github/workflows/called-workflow.yml#v1
job2:
runs-on: ubuntu-latest
needs: job1
steps:
- run: echo ${{ needs.job1.outputs.firstword }} ${{ needs.job1.outputs.secondword }}
How could the message action be triggered after build action is completed?
This should now (August 2020) be possible with "GitHub Actions improvements for fork and pull request workflows"
Another frequently-requested feature for Actions is a way to trigger one workflow based on the completion of another workflow.
For example, you may want to take the results of a CI workflow and run some further analysis.
The new workflow_run event enables you to trigger a new workflow when one or more workflows are requested or completed.
Runs triggered by the workflow_run event always use the default branch for the repository, and have access to a read/write token as well as secrets.
As an example, as a maintainer you could set up a workflow that takes the artifacts generated by the pull request workflow, do some analysis, and post comments back to the pull request.
This event is also available as a web hook.

Can I filter a GitHub action step based on the commit message?

I've recently added a static analysis step to my GitHub actions. However, it is somewhat expensive so I'm trying to reduce the number of times that this step is run. I've already added an appropriate filter so that it only runs on one OS and so that it only runs on my "feature" branches. However, I would like to also filter out any checkins that include "WIP" in their commit message. (The theory being that there is no point in performing the full analysis until it is no longer a "Work In Progress".)
I've searched through the docs, expecting I would find an object I could use as part of the github context object, but to no avail.
Any ideas on how I can accomplish this goal?
If you want to see exactly what I'm doing, the action Yaml is as follows. I'm hoping to find some change I can make to the if statement on the Static Analysis item that would accomplish my goal.
name: On Push
on: [push]
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout#v1
- name: Build
run: |
./configure
make -j 4
- name: Run tests
run: |
make -j 4 check
- name: Static Analysis
if: runner.os == 'macOS' && startsWith(github.ref, 'refs/heads/feature/')
run: |
make analyze
You can make use of the event property on the github context to access the push payload.
Add the following to the step that does the analysis:
if: !startsWith(github.event.head_commit.message, 'WIP')
Related to your issue, you now (Feb. 2021) have:
GitHub Actions: Skip pull request and push workflows
with [skip ci]
GitHub Actions now supports skipping push and pull_request workflows by looking for some common keywords in your commit message.
If any commit message in your push or the HEAD commit of your PR contains the strings [skip ci], [ci skip], [no ci], [skip actions], or [actions skip] workflows triggered on the push or pull_request events will be skipped.
This is not as flexible as a custom commit message (like your "WIP"), but it still can help.
if: ${{ !startsWith(github.event.head_commit.message, '#NORUN') }}
Syntax should be like this