Skip to content
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

Write GitHub Action for package/tag version verification (avoid duplication of code in GitHub Actions) #21

Open
kniklas opened this issue Apr 9, 2021 · 1 comment
Labels
DevOps help wanted Extra attention is needed
Milestone

Comments

@kniklas
Copy link
Owner

kniklas commented Apr 9, 2021

Currently both publishing workflows: publish-dev.yml and publish-master.yml use duplicated code which verifies if tag version is the same as checked out python package version (stored in src/getfx/__init__.py.

Ideally this duplicated code should be replaced with a new GitHub Action:

  • preferably should be written in Node.js (preferred over docker as it takes at least 15-30s to build an image)
  • (nice to have) such action should use repository (or environment) secret to run or not (by default run)

Example of code snippet to be converted to GitHub Action:

      - name: Set variables
        id: get_version
        run: |
          echo ::set-output name=TAG_VER::$(echo $GITHUB_REF | cut -d / -f 3)
          echo "GETFX_SRC_VER=v$(cat src/getfx/__init__.py | grep version | awk -F"= " '{ print $2 }' | sed 's/"//g')" >> $GITHUB_ENV
          echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-8)" >> $GITHUB_ENV
      - name: Fail if SRC and GIT TAG versions are different
        if: env.GETFX_SRC_VER != steps.get_version.outputs.TAG_VER
        uses: actions/github-script@v3
        with:
          script: core.setFailed('Different tag and SRC versions ${{ steps.get_version.outputs.TAG_VER}} vs ${{ env.GETFX_SRC_VER}}')

Note:

  • first and second echo commands are specific to the new GitHub action and can be replaced by it
  • third echo command is required only by later parts of workflow action which uses it for publishing documentation (it should remain in workflow action)

Note on using secrets in if: statements
There was an attempt to add in if: statement secret that would indicate if this check should be performed, but after few trials it was not successful. Probably this can be overcome (https://stackoverflow.com/questions/61255989/dynamically-retrieve-github-actions-secret) but apparently secrets can't be used for that purpose: actions/runner#520

Additionally following link could be check if will be useful: https://github.com/marketplace/actions/secret-input-gate

Not sure if this problem will manifest for new GitHub Action.

@kniklas kniklas added DevOps help wanted Extra attention is needed labels Apr 9, 2021
@kniklas
Copy link
Owner Author

kniklas commented Oct 27, 2021

@kniklas kniklas changed the title Write GitHub Action for package/tag version verification Write GitHub Action for package/tag version verification (avoid duplication of code in GitHub Actions) Oct 27, 2021
@kniklas kniklas added this to the v0.1.4 milestone Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DevOps help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant