I was using the workflow below in a project. However, I wanted to share this with other people and figured posting it as a GitHub Action to the marketplace would be the most user-friendly option. I created a new repo with action.yml and other required files. However, even after editing the workflow, I was unable to get past the Set up job stage. I would like to know which tweaks I need to make in order to have a valid action.yml that does the same as the original workflow as I don't have any experience with this yet. The original workflow, action.yml and error message can be found below. The original workflow works as intended, but not when executed by the uses keyword.
Original workflow (works as intended):
name: Yaml autosync
description: Auto-sync changes to a template YAML localisation file to all other YAML files in the same directory.
branding:
icon: file-text
color: blue
inputs:
lang_path:
description: 'Path to the folder that contains all lang files'
default: .
required: false
default_file:
description: 'The name of the YAML file that contains all default options. These values are used to fill in any missing info in the other files.'
default: 'default.yml'
required: false
github_token:
description: 'The secret GitHub Token so this action has push access. Make sure to use GitHub secrets and do not push any private info!'
required: true
on: [push]
jobs:
build:
runs-on: ubuntu-latest
env:
LANG_PATH: ${INPUT_LANG_PATH}
DEFAULTS: ${INPUT_DEFAULT_FILE}
steps:
- uses: actions/checkout#v2
with:
persist-credentials: false
fetch-depth: 0
- name: Set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Clone YAML-localisation-sync
run: git clone some_repo
- name: Building the project
run: |
cd YAML-localisation-sync
mvn package
- name: Moving JAR file
run: cp YAML-localisation-sync/target/YamlLocalisation.jar ${LANG_PATH}
- name: Running JAR file
run: |
cd ${LANG_PATH}
java -jar YamlLocalisation.jar ${DEFAULTS}
- name: Repo cleanup
run: |
rm -rf YAML-localisation-sync
cd ${LANG_PATH}
rm YamlLocalisation.jar
- name: Commit changes
run: |
git config --local user.email "41898282+github-actions[bot]#users.noreply.github.com"
git config --local user.name "YAML sync bot"
git add .
git commit -m "Sync YAML localisation files"
git fetch
continue-on-error: true
- name: Push changes
uses: ad-m/github-push-action#master
with:
github_token: ${INPUT_GITHUB_TOKEN}
force: true
Action.yml (workflow above, updated to work as a GitHub Action on the marketplace)
name: Yaml autosync
description: Auto-sync changes to a template YAML localisation file to all other YAML files in the same directory.
branding:
icon: file-text
color: blue
inputs:
lang_path:
description: 'Path to the folder that contains all lang files'
default: .
required: false
default_file:
description: 'The name of the YAML file that contains all default options. These values are used to fill in any missing info in the other files.'
default: 'default.yml'
required: false
github_token:
description: 'The secret GitHub Token so this action has push access. Make sure to use GitHub secrets and do not push any private info!'
required: true
on: [push]
runs:
using: "composite"
env:
LANG_PATH: ${INPUT_LANG_PATH}
DEFAULTS: ${INPUT_DEFAULT_FILE}
steps:
- run: git clone https://github.com/MyProfile/YAML-localisation-sync.git
shell: bash
- run: |
cd YAML-localisation-sync
mvn package
shell: bash
- run: cp YAML-localisation-sync/target/YamlLocalisation.jar ${LANG_PATH}
shell: bash
- run: |
cd ${LANG_PATH}
java -jar YamlLocalisation.jar ${DEFAULTS}
shell: bash
- run: |
rm -rf YAML-localisation-sync
cd ${LANG_PATH}
rm YamlLocalisation.jar
shell: bash
run: |
git config --local user.email "41898282+github-actions[bot]#users.noreply.github.com"
git config --local user.name "YAML sync bot"
git add .
git commit -m "Sync YAML localisation files"
git fetch
shell: bash
continue-on-error: true
Workflow that has the error (in a repo that is used to test the published GitHub action)
name: GitHub Actions
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
with:
persist-credentials: false
fetch-depth: 0
- name: Set up JDK 1.8
uses: actions/setup-java#v1
with:
java-version: 1.8
- name: Yaml autosync
uses: MyProfile/MyRepo#15
with:
github_token: ${secrets.GITHUB_TOKEN}
lang_path: foldertest/
default_file: en.yml
Error message
Current runner version: '2.277.1'
Operating System
Virtual Environment
GITHUB_TOKEN Permissions
Prepare workflow directory
Prepare all required actions
Getting action download info
Download action repository 'actions/checkout#v2'
Download action repository 'actions/setup-java#v1'
Download action repository 'MyProfile/MyAction#15'
Error: MyProfile/MyAction/15/action.yml (Line: 28, Col: 3): Unexpected value 'steps'
Error: MyProfile/MyAction/15/action.yml (Line: 28, Col: 3): Unexpected value 'steps'
Error: System.ArgumentNullException: Value cannot be null. (Parameter 'You are using a composite action but there are no steps provided in MyProfile/MyAction/15/action.yml.')
at GitHub.Runner.Worker.ActionManifestManager.ConvertRuns(IExecutionContext executionContext, TemplateContext templateContext, TemplateToken inputsToken, String fileRelativePath, MappingToken outputs)
at GitHub.Runner.Worker.ActionManifestManager.Load(IExecutionContext executionContext, String manifestFile)
Error: Fail to load MyProfile/MyAction/15/action.yml
Related
I would like to publish a Python package to pypi if merging to master OR a file named VERSION contains letter b. The VERSION file is located in the root of this repo.
I'm able to get the "merging to master" part work with the following code.
publish:
needs: [build]
runs-on: [self-hosted, generic-linux]
container: python:3
steps:
- name: Download artifacts
uses: actions/download-artifact#v2
with:
name: package
path: ./dist
- name: Install requirements
run: |
pip install --upgrade pip
pip install --upgrade --prefer-binary twine
- name: Upload to artifactory
if: ${{ github.ref == 'refs/heads/master' }}
env:
TWINE_REPOSITORY_URL: https://artifactory.example.com/artifactory/api/pypi/pypi-all
TWINE_REPOSITORY: pypi-all
TWINE_USERNAME: "${{ secrets.PUBLISH_USERNAME }}"
TWINE_PASSWORD: "${{ secrets.PUBLISH_BEARER_TOKEN }}"
run: |
twine upload --skip-existing --verbose dist/*
However, I'm not sure how to add an OR condition to check the content of a file. Could someone help?
Thanks.
you could add an extra step to read the content (manually or using some existing GH action like https://github.com/marketplace/actions/read-files-action) of the file and add a condition the the Upload step, to check if the file contains the required string (with https://docs.github.com/en/actions/learn-github-actions/expressions#contains), like:
- name: Checkout code
uses: actions/checkout#v3
- name: Read Version
id: version
uses: komorebitech/read-files-action#v1.5
with:
files: '["VERSION"]'
- name: Echo Version
run: echo "${{ steps.version.outputs.content }}"
- name: Upload to artifactory
if: ${{ github.ref == 'refs/heads/master' || contains(steps.version.outputs.content, 'b')}}
Remember to checkout the code of the repo before try to read the file
I have enabled Github actions to create Tech docs after a commit. Below is the workflow file written to create Md files. But "techdocs-cli generate --no-docker --verbose" command fails with the below error. Can someone please help with the issue?
Failed to generate docs from /home/runner/work/myapp3/myapp3 into /home/runner/work/myapp3/myapp3/site; caused by unknown error 'Command mkdocs failed, exit code: 1'
workflow file:
name: Publish TechDocs Site
on:
push:
branches: master
jobs:
publish-techdocs-site:
runs-on: ubuntu-latest
env:
TECHDOCS_S3_BUCKET_NAME: XXX
AWS_ACCESS_KEY_ID: XXX
AWS_SECRET_ACCESS_KEY: XXX
AWS_REGION: XXX
ENTITY_NAMESPACE: 'default'
ENTITY_KIND: 'Component'
ENTITY_NAME: ‘XXX’
steps:
- name: Checkout code
uses: actions/checkout#v2
- uses: actions/setup-node#v2
- uses: actions/setup-python#v2
- name: Install techdocs-cli
run: sudo npm install -g #techdocs/cli
- name: Install mkdocs and mkdocs plugins
run: python -m pip install mkdocs-techdocs-core==1.*
- name: Generate docs site
run: techdocs-cli generate --no-docker --verbose
- name: Publish docs site
run: techdocs-cli publish --publisher-type awsS3 --storage-name $TECHDOCS_S3_BUCKET_NAME --entity $ENTITY_NAMESPACE/$ENTITY_KIND/$ENTITY_NAME
I had the same issue and it was resolved once you had the right folder structure where you have the mkdocs.yml file.
As long as you have a docs folder in the same root structure with the .md file that needs to be published.
The same .md file needs to be configured in the navigation section of the mkdocs.yml file as well
On a github repository my_repo, I could correctly set up github actions to trigger build, tests and documentation:
name: CMake
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Install dependencies
run: sudo apt-get install -y --no-install-recommends libboost-all-dev libgdal-dev doxygen graphviz
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}
- name: Docs
working-directory: ${{github.workspace}}/build
run: make doc
I also implemented Release Drafter to automate the process of bumping versions:
name: Release Drafter
on:
push:
branches:
- master
pull_request:
types: [opened, reopened, synchronize]
jobs:
update_release_draft:
runs-on: ubuntu-latest
steps:
- uses: release-drafter/release-drafter#v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Now, I would like to automate the following:
a major version is released in the repo my_repo
this triggers an event in my Github Pages repo
the documentation is built in my Github Pages repo in the folder softs/my_repo/docs
the website is published (that is equivalent to commiting the changes and pushing the master branch)
I don't exactly know how to implement that. Should I write a github workflow in my Github pages to "listen" what is happening in the my_repo project? Also, I can I forward the version from the my_repo to Doxygen?
I ended up being able to reach my goals. I will post this sample code in case it could benefit the next beginner with Github Action to automate the documentation building:
name: CMake
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team#latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
with:
# we want to find git tags to pass version to doxygen
fetch-depth: 0
- name: Install quetzal and Doxygen dependencies
run: sudo apt-get install -y --no-install-recommends libboost-all-dev libgdal-dev doxygen graphviz
- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}}
- name: Generate documentation
working-directory: ${{github.workspace}}/build
# this is defined in the repo docs/CMakeLists.txt file
run: make docs
- name: Moving Files
run: |
mv ${{github.workspace}}/build/docs/html ./docs/api
# Deploy to GitHub Pages
- name: Deploy
uses: peaceiris/actions-gh-pages#v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./
In the project/docs/CMakeLists.txt:
# look for Doxygen package
# Require dot, treat the other components as optional
find_package(Doxygen
REQUIRED dot
OPTIONAL_COMPONENTS mscgen dia)
if(DOXYGEN_FOUND)
# exclude sqlite code
set(DOXYGEN_EXCLUDE_PATTERNS
*/sqlite3/*
)
# doxygen settings can be set here, prefixed with "DOXYGEN_"
set(DOXYGEN_PROJECT_NAME "my-project")
set(DOXYGEN_INPUT "mainpage.md")
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "mainpage.md")
set(DOXYGEN_EXCLUDE_PATTERNS "README.md")
set(DOXYGEN_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/docs")
# this target will only be built if specifically asked to.
# run "make docs" to create the doxygen documentation
doxygen_add_docs(
docs
${PROJECT_SOURCE_DIR}
COMMENT "Generate API-documents for NoteSearch."
)
endif(DOXYGEN_FOUND)
To automatically retrieve the version number and pass it to Doxygen (as well as to the C++ code), I could adapt the solution given by Brian Milco here: https://ipenguin.ws/2012/11/cmake-automatically-use-git-tags-as.html .
They posted the solution in 2012, so there may be easier ways to do the same thing in 2022. But, as far as I am concerned, it works for me!
In the root CMakeLists.txt:
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
#
# VERSIONING
#
# Appends the cmake/modules path to MAKE_MODULE_PATH variable.
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
include(GetGitRevisionDescription)
git_describe(VERSION --tags --dirty=-d)
#parse the version information into pieces.
string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.[0-9]+(.*)" "\\1" VERSION_SHA1 "${VERSION}")
set(VERSION_SHORT "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/version.cpp.in
${CMAKE_CURRENT_BINARY_DIR}/version.cpp)
set(version_file "${CMAKE_CURRENT_BINARY_DIR}/version.cpp")
#Add the version_file to the executables being built or it won't compile.
#add_executable(${PROJECT_NAME} ${source_files} ${ui_files} ${version_file})
#
# PROJECT DESCRIPTION
#
project(
"project_name"
LANGUAGES CXX
VERSION ${VERSION_SHORT}
This sets the CMake project version to the automatically retrieved git version tag, and it is passed to the Doxygen module by a default on set(DOXYGEN_PROJECT_NUMBER $(PROJECT_VERSION).
A complete working solution can be find on my project at https://github.com/Becheler/quetzal-CoalTL/commit/2ef5851cc6a34391d7a9ea64fb7c7122feb23b0a
I'm trying to automate upload of my NuGet package using GitHub actions. I was hoping I could match the file name which includes the version number to avoid having to hardcode it in the action YML. It works if I hardcode the file name. I guess I just need to understand the syntax to use file pattern match. See last line of that code sample:
name: .NET
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
defaults:
run:
working-directory: ./Project
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- name: Setup .NET
uses: actions/setup-dotnet#v1
with:
dotnet-version: 5.0.x
- name: Restore dependencies
run: dotnet restore SharpLibHid.sln
- name: Build debug
run: dotnet build SharpLibHid.sln --no-restore -c Debug
- name: Build release
run: dotnet build SharpLibHid.sln --no-restore -c Release
- name: Test
run: dotnet test SharpLibHid.sln --no-build --verbosity normal
- name: Publish Nuget
run: dotnet nuget push './Hid/bin/Release/SharpLibHid.*.nupkg' --skip-duplicate -k ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json
How do you use file matching pattern in GitHub actions run?
Here is a successful build with hardcoded path:
https://github.com/Slion/SharpLibHid/actions/runs/998451423
Here is a failed build with my attempt at pattern matching:
https://github.com/Slion/SharpLibHid/actions/runs/998464157
My objective is to get to the point where I can type /run-black as a comment on a pull request in GitHub, and then GitHubActions will run black . on the pull request's branch and add a commit.
The use case is that sometimes casual contributors make a small pull request to my library (e.g. fixing a typo), and I'd like to be able to just write a comment like /run-black to have the black formatter run on their files before I merge.
Use the action Slash Command Dispatch. Add a repo scoped PAT with the name PAT to your secrets and create two workflows with the following definitions.
name: Slash Command Dispatch
on:
issue_comment:
types: [created]
jobs:
slashCommandDispatch:
runs-on: ubuntu-latest
steps:
- name: Slash Command Dispatch
uses: peter-evans/slash-command-dispatch#v2
with:
token: ${{ secrets.PAT }}
issue-type: pull-request
commands: |
run-black
on:
repository_dispatch:
types: [run-black-command]
jobs:
runBlack:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
with:
repository: ${{github.event.client_payload.pull_request.head.repo.full_name}}
ref: ${{github.event.client_payload.pull_request.head.ref}}
token: ${{ secrets.PAT }}
- name: Slash Command Dispatch
run: black .
- run: |
git config --local user.email "41898282+github-actions[bot]#users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git commit -m "Run black" -a
git push