changes:
name: Detect changes
runs-on: ubuntu-latest
outputs:
aws: ${{ steps.filter.outputs.aws }}
azure: ${{ steps.filter.outputs.azure }}
gcp: ${{ steps.filter.outputs.gcp }}
steps:
- name: Checkout source code
uses: actions/checkout#v2
- name: Check for changes
uses: dorny/paths-filter#v2
id: filter
with:
filters: |
aws:
- added|modified: 'aws/**'
azure:
- added|modified: 'azure/**'
gcp:
- added|modified: 'gcp/**'
zip_files:
runs-on: ubuntu-latest
needs: changes
steps:
- uses: actions/checkout#v2
- uses: montudor/action-zip#v1
with:
args: zip -qq -r result.zip "$(${{needs.changes.outputs.aws}} && echo aws)" "$(${{needs.changes.outputs.azure}} && echo azure)" "$(${{needs.changes.outputs.gcp}} && echo gcp)"
- uses: actions/upload-artifact#v1
with:
name: my-artifact
path: ${{ github.workspace }}/result.zip
I want to zip directories that detect changes. and then upload it to artifact.
When zipping, I get a "zip error: Nothing to do" even though aws/azure/gcp all evaluate to true. I think that the error lies within the args line.
Related
Given the following sample workflow
name: My workflow
on:
push:
branches:
- 'main'
jobs:
job_1:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout#v3
with:
fetch-depth: 0
- name: Get next version
id: get_next_version
uses: thenativeweb/get-next-version#2.5.0
- name: Echo for new version
if: ${{ steps.get_next_version.outputs.hasNextVersion == 'true' }}
run: echo there is a new version
- name: Echo for no new version
if: ${{ steps.get_next_version.outputs.hasNextVersion != 'true' }}
run: echo there is no new version
job_2:
needs: job_1
if: needs.job_1.steps.get_next_version.outputs.hasNextVersion == 'true'
runs-on: ubuntu-latest
steps:
- name: First step
run: echo job_2 is running
The action get-next-version analyzes my commit and calculates a new version. As you can see in job_1 I can access the calculated result.
job_2 depends on job_1 and should only run if there would be a new version. I tried to access the result in the if statement of job_2 but it seems that didn't work, I might be using the wrong syntax.
I get the echo
there is a new version
but job_2 was skipped. Is there a way to get access to the data of get_next_version.outputs ( I want the fields hasNextVersion and version )?
Yes - it's possible.
Each job can define its output as an output of one of its steps.
The related documentation can be found here
name: My workflow
on:
push:
branches:
- 'main'
jobs:
job_1:
runs-on: ubuntu-latest
# define output for first job forwarding output of hasNextVersionOutput job
outputs:
hasNextVersion: ${{ steps.hasNextVersionOutput.outputs.hasNextVersion }}
steps:
- name: Checkout repository
uses: actions/checkout#v3
with:
fetch-depth: 0
- name: Get next version
id: get_next_version
uses: thenativeweb/get-next-version#2.5.0
# add a step to generate the output that will be read by the job
- name: Generate output
run: echo "hasNextVersion=${{
steps.get_next_version.outputs.hasNextVersion }}" >> $GITHUB_OUTPUT
- name: Echo for new version
if: ${{ steps.get_next_version.outputs.hasNextVersion == 'true' }}
run: echo there is a new version
- name: Echo for no new version
if: ${{ steps.get_next_version.outputs.hasNextVersion != 'true' }}
run: echo there is no new version
job_2:
needs: job_1
# read output directly from job (you cannot access its steps
if: needs.job_1.outputs.hasNextVersion == 'true'
runs-on: ubuntu-latest
steps:
- name: First step
run: echo job_2 is running
I'm trying to integrate Lighthouse CI into my CI/CD to generate reports on my applications performance. I'm using GitHub Actions, and other jobs like building the app and generating a SonarCloud scan are working.
However Lighthouse CI is not working. The error is: Error: fatal: could not read Username for 'https://github.com': terminal prompts disabled
Code:
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
sonarcloud:
name: SonarCloud
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action#master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
lighthouse:
name: Lighthouse CI
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout#v3
with:
token: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
submodules: recursive
- name: Use Node.js 16.x
uses: actions/setup-node#v3
with:
node-version: 16.x
- name: Run the Lighthouse CI
run: |
npm install -g #lhci/cli#0.6.x
lhci autorun
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
node-version: [ 16.x ]
steps:
- uses: actions/checkout#v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm test
- name: Log in to the Container registry
uses: docker/login-action#f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action#98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=sha
- name: Build and push Docker image
uses: docker/build-push-action#ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Screenshot of GitHub Actions:
hi,i find a issue for the problem。
https://github.com/actions/checkout/issues/664
“For a simple checkout indeed no PAT is required.”
so you can try remove token
lighthouse:
name: Lighthouse CI
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout#v3
with:
# token: ${{ secrets.LHCI_GITHUB_APP_TOKEN }} // remove
submodules: recursive
- name: Use Node.js 16.x
uses: actions/setup-node#v3
with:
node-version: 16.x
- name: Run the Lighthouse CI
run: |
npm install -g #lhci/cli#0.6.x
lhci autorun
I have the below github actions where i am storing the release version in manager job and using it in the deployment with manager-uat and manager-production and a weird thing is happening that i get the output current_version available in manager-uat but not in manager-production whereas i am referring to the same variable. Please can somebody suggest.
manager:
runs-on: ubuntu-latest
outputs:
CURRENT_VERSION: ${{ steps.status.outputs.CURRENT_VERSION }}
NEED_RELEASE: ${{ steps.status.outputs.NEED_RELEASE }}
steps:
- uses: actions/checkout#v2
- <more steps>
- name: manager - Check the current version
working-directory: .
run: |
echo "CURRENT_VERSION=$(python tools/check_version.py manager)" >> $GITHUB_ENV
- id: status
run: |
echo "::set-output name=CURRENT_VERSION::${{ env.CURRENT_VERSION }}"
echo "::set-output name=NEED_RELEASE::${{ env.NEED_RELEASE }}"
manager_uat:
needs: [manager]
if: needs.manager.outputs.NEED_RELEASE == 'true'
uses: ./.github/workflows/cd_mlops.yml
secrets: inherit
with:
version: ${{needs.manager.outputs.CURRENT_VERSION}}
service: manager
envir: uat
manager_production:
needs: [ manager_uat ]
if: needs.manager.outputs.NEED_RELEASE == 'true'
uses: ./.github/workflows/cd_mlops.yml
secrets: inherit
with:
version: ${{needs.manager.outputs.CURRENT_VERSION}}
service: manager
envir: production
You cannot use needs.X if X is not a direct dependency of the job.
So in your case, you need to add manager as a dependency of manager_production like so:
manager_production:
needs: [ manager, manager_uat ]
if: needs.manager.outputs.NEED_RELEASE == 'true'
uses: ./.github/workflows/cd_mlops.yml
# ..etc
My workflow has 2 jobs:
job "build" creates a zip and uploads it as an artifact
job "deploy" downloads this artifact and (tries to) unzip it
Here is a simplified version of the workflow:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: action-zip
uses: montudor/action-zip#v1.0.0
with:
args: zip -qq -r azfunc-repository-stats.zip .
- name: Upload artifact
uses: actions/upload-artifact#v2
with:
name: azfunc-repository-stats-app
path: ${{ github.workspace }}/azfunc-repository-stats.zip
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: 'Download artifact'
uses: actions/download-artifact#v2
with:
name: azfunc-repository-stats-app
path: ${{ runner.temp }}
- name: Debug
run: |
ls -al ${{ runner.temp }}
id
chmod 777 ${{ runner.temp }}/azfunc-repository-stats.zip
cp ${{ runner.temp }}/azfunc-repository-stats.zip ${{ runner.temp }}/azfunc-repository-stats2.zip
ls -al ${{ runner.temp }}
- name: 'Unzip project'
uses: montudor/action-zip#v1.0.0
with:
args: unzip -qq ${{ runner.temp }}/azfunc-repository-stats.zip -d ${{ github.workspace }}
Everything works fine (including Debug step), up to the step Unzip project which fails with this error :
unzip: cannot find or open /home/runner/work/_temp/azfunc-repository-stats.zip, /home/runner/work/_temp/azfunc-repository-stats.zip.zip or /home/runner/work/_temp/azfunc-repository-stats.zip.ZIP.
I know it exists because my Debug step does output it, and can find/copy it with no problem
It is exactly the same problem if:
I download the archive in ${{ github.workspace }} instead of ${{ runner.temp }}
I use action TonyBogdanov/zip#1.0 instead of montudor/action-zip#v1.0.0 to unzip the artifact
I have read through the documentation for Github actions and the release action, yet I can find nothing on how to get the name from the action. Do I need to run a fetch call or something else?
name: Publish to Bintray
on:
release:
types: [published]
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew curseforge uploadSubProjects publishToModrinth --parallel --stacktrace
env:
BINTRAY_USER: oroarmor
BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }}
CURSE_API_KEY: ${{ secrets.CURSE_API_KEY }}
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
You can use github.event.release.name and github.event.release.body:
name: After Release
on:
release:
types: [published]
jobs:
after-release:
runs-on: ubuntu-latest
steps:
- run: echo "Name: ${{ github.event.release.name }} Description: ${{ github.event.release.body }}"