Get the current pushed tag in Github Actions

前端 未结 4 455
别跟我提以往
别跟我提以往 2021-01-31 08:12

Is there a way to access the current tag that has been pushed in a Github Action? In CircleCI you can access this value with the $CIRCLE_TAG variable.

My Wor

4条回答
  •  遇见更好的自我
    2021-01-31 09:16

    So thanks to all the help from @peterevans I managed to achieve the result I wanted which was:

    • to tag a commit
    • push the tag to trigger the github action
    • github action sets the git tag as an env var
    • run install & build
    • use chrislennon/action-aws-cli action to install aws cli using secrets for keys
    • run command to sync the build to a new S3 bucket using the tag env var as the dir name

    Here is an example of the what I ran using Chris Lennon's action:

    on:
      push:
        tags:
          - 'v*.*.*'
    jobs:
      test:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v1
          - name: Set env
            run: echo ::set-env name=RELEASE_VERSION::$(echo ${GITHUB_REF:10})
          - name: yarn install & build
            run: |
              yarn install
              yarn build
          - uses: chrislennon/action-aws-cli@v1.1
          - name: Publish to AWS S3
            env:
              AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
              AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
              AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }}
            run: aws s3 sync dist s3://$AWS_S3_BUCKET/$RELEASE_VERSION/ --acl public-read
    

提交回复
热议问题