-
Notifications
You must be signed in to change notification settings - Fork 38
Workflow to create GFM artifact(s) #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 23 commits
a7637dd
8b3e1e6
07645b7
1a525a5
f11fb70
a1928a1
4d99cd3
fdb938f
a6bafc0
3ebd89e
d81f735
82760d9
27bd12b
f5246ff
79a0543
a24b728
4fd637e
7250700
b291ad1
c4a18f7
03b50bb
f71bf33
c7426f7
3d03a54
852cdd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| name: Build GFM artifacts | ||
|
|
||
| # Builds the GFM library as artifacts that can be used by other workflows | ||
| # | ||
| # It checks for any existing artifacts with an expiry date at least 10 days after today | ||
| # If none are found, the library is built and uploaded. | ||
|
|
||
| # This workflow can be run on demand, but is intended to be run on a weekly schedule | ||
| # This should ensure that there is always at least one artifact available but no more than 2 | ||
|
|
||
| on: | ||
| # Schedule once a week | ||
| schedule: | ||
| - cron: '11 12 * * 0' | ||
| push: | ||
| paths: | ||
| - '**/build-artifacts.yml' # self | ||
| - 'pelican/build-cmark.sh' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build-artifact: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| # Allow for multiple versions to be maintained | ||
| matrix: | ||
| gfm_version: | ||
| - '0.28.3.gfm.12' | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| persist-credentials: false | ||
| - name: Fetch and build version ${{ matrix.gfm_version }} | ||
| id: build_gfm | ||
| run: | | ||
| # N.B. This must agree with the definition in pelican/action.yml | ||
| export GFM_ARTIFACT_KEY=gfm-lib-${{ matrix.gfm_version }} | ||
| echo "GFM_ARTIFACT_KEY=${GFM_ARTIFACT_KEY}" >> $GITHUB_ENV | ||
| # Check if artifact is present (list all) | ||
| curl -sS https://api.github.com/repos/$GITHUB_REPOSITORY/actions/artifacts?name=${GFM_ARTIFACT_KEY} >/tmp/artifact.json | ||
| # when does last one expire? | ||
| jq </tmp/artifact.json '[.artifacts[]|select(.expired==false)|.expires_at]|max' >/tmp/max.txt | ||
| # is that more than 10 days away? (86400*10 seconds) | ||
| OUT=$(jq </tmp/max.txt 'select(.>(now+864000|strftime("%FT%TZ")))') | ||
| if [[ -n $OUT ]] | ||
| then | ||
| echo "Found a valid artifact for ${{ matrix.gfm_version }} (expires $OUT)" | ||
| exit 0 # No more to do | ||
| fi | ||
| echo "Could not find a valid artifact for ${{ matrix.gfm_version }}; building another" | ||
| # build GFM and set up LIBCMARKDIR | ||
| export LIBCMARKDIR=/tmp/gfm-${{ matrix.gfm_version }} | ||
| mkdir -p ${LIBCMARKDIR} | ||
| bash $GITHUB_WORKSPACE/pelican/build-cmark.sh ${{ matrix.gfm_version }} ${LIBCMARKDIR} | ||
| # Tell the save step what to save | ||
| echo "created=${LIBCMARKDIR}" | tee -a $GITHUB_OUTPUT | ||
| - name: Save the GFM build ${{ matrix.gfm_version }} | ||
| if: ${{ steps.build_gfm.outputs.created }} | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: ${{ env.GFM_ARTIFACT_KEY }} | ||
| path: ${{ steps.build_gfm.outputs.created }} | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,34 +51,55 @@ runs: | |
| # If the site uses Github Flavored Markdown, use this build branch | ||
| - name: fetch and build libcmark-gfm.so | ||
| if: ${{ inputs.gfm == 'true' }} | ||
| id: build_gfm | ||
| shell: bash | ||
| env: | ||
| WORKDIR: /opt/pelican-asf # where to build GFM | ||
| GFM_VERSION: '0.28.3.gfm.12' # ensure we agree with build-cmark.sh script | ||
| # action_repository only works in the env context; empty for local action call | ||
| # it is always empty for local invocation, in which case use the current repo | ||
| GITHUB_ACTION_REPO: ${{ github.action_repository || github.repository }} | ||
| GH_TOKEN: ${{ github.token }} # needed by gh | ||
| run: | | ||
| # The key needs to include the GFM version, but is otherwise arbitrary. | ||
| # It must agree with the definition in build-actions.yml | ||
| export GFM_ARTIFACT_KEY=gfm-lib-${GFM_VERSION} | ||
|
|
||
| if [[ -z $LIBCMARKDIR ]] # define LIBCMARKDIR if it is not already | ||
| then | ||
| # set up the GFM environment | ||
| export LIBCMARKDIR=/opt/pelican-asf/gfm-${GFM_VERSION} # arbitrary, but should contain version | ||
| mkdir -p $LIBCMARKDIR | ||
| echo "LIBCMARKDIR=${LIBCMARKDIR}" >>$GITHUB_ENV # needed for the build step | ||
| fi | ||
|
|
||
| # Does the GFM build already exist? | ||
| if [[ -n $LIBCMARKDIR && -d $LIBCMARKDIR ]] | ||
| if [[ -f $LIBCMARKDIR/libcmark-gfm.so ]] | ||
| then | ||
| echo "Already have GFM binary at $LIBCMARKDIR, skipping build" | ||
| exit 0 # nothing more to do in this step | ||
| fi | ||
|
|
||
| # Is there a saved artifact for the GFM build? | ||
| echo "Check for GFM build artifact in action repo: $GITHUB_ACTION_REPO" | ||
| gh run download --dir ${LIBCMARKDIR} --name ${GFM_ARTIFACT_KEY} --repo $GITHUB_ACTION_REPO || true | ||
| if [[ -f $LIBCMARKDIR/libcmark-gfm.so ]] | ||
| then | ||
| echo "Downloaded to ${LIBCMARKDIR} from $GITHUB_ACTION_REPO, nothing more to do!" | ||
| exit 0 # nothing more to do in this step | ||
| fi | ||
|
|
||
| # GFM binary not found, need to build it | ||
| { | ||
| echo "Creating GFM binary in ${LIBCMARKDIR}" | ||
| # disable stdout unless debug is on | ||
| if [ "${{ inputs.debug }}" == 'true' ] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's nice if you automatically debug on rerun... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that you should also move this to an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I realise that. Except perhaps $(( github.xxx }} for some values of xxx There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for most of those, github has a $GITHUB_..., so you really should never do it :)... it's a safe enough rule.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AIUI, |
||
| then | ||
| DEBUG_STEPS=1; export DEBUG_STEPS | ||
| else | ||
| exec >/dev/null | ||
| fi | ||
| # Don't pollute site checkout | ||
| mkdir -p $WORKDIR | ||
| pushd $WORKDIR | ||
| # build the code and define LIBCMARKDIR | ||
| bash ${{ github.action_path }}/build-cmark.sh $GFM_VERSION | grep "export LIBCMARKDIR" >/tmp/libcmarkdir.$$ | ||
| source /tmp/libcmarkdir.$$ | ||
| popd | ||
| # ensure LIBCMARKDIR is defined for subsequent steps | ||
| echo "LIBCMARKDIR=${LIBCMARKDIR}" >> $GITHUB_ENV | ||
| # build the code and define LIBCMARKDIR under $WORKDIR | ||
| bash ${{ github.action_path }}/build-cmark.sh $GFM_VERSION $LIBCMARKDIR | ||
| } | ||
|
|
||
| - name: Generate website from markdown | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should never use
${{ ... }}inside arun:block.use:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on what you're doing, it can result in security vulnerabilities or very surprising misbehaviors.
In this case, if your matrix was:
then you'd be constructing a script of the form:
which is fairly surprising.
https://github.com/check-spelling-sandbox/sturdy-adventure/actions/runs/13166687061/job/36748420310#step:6:14
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks for the explanation.
It seems unlikely that the matrix would contain such a value, but I agree it is safer to protect the code by using an intermediate variable.